How to show the "days" that return in the request?

Asked

Viewed 27 times

0

I’m programming in JS for React-Native and I’m having trouble showing off in FLATLIST of the days of the week (will be names of users later) coming in the Array.

class alunoAgenda extends Component {

        componentDidMount = () => {
            this.props.contatosUsuarioFetchDOIS()
        }

      render() {
        return (
          <View style={styles.container}>
                <FlatList
                data={this.props.diaSemana}
                renderItem={({ item }) => <Item key={item.id} {...item} />}
                keyExtractor={item => item.id}
                />
          </View>
        )

      }
    }

Action Code contact yourFetchDOIS:

export const setTime = diaSemana => {
    return {
        type: SET_TIME_DOIS,
        payload: diaSemana,
    }
}

export const contatosUsuarioFetchDOIS = () => {
        return dispatch => {
            axios.get('https://my-rugby-fit.firebaseio.com/HorarioDoisVagas.json')
                .catch(err => console.log('não foi possível'))
                .then(res => {
                    const rawdiaSemana = res.data
                    const diaSemana = []
                    for (let key in rawdiaSemana) {
                        diaSemana.push({
                            ...rawdiaSemana[key],
                            id: key
                    })
                }

                dispatch(setTime(diaSemana))
            })
        }
 }
  • What is the actual purpose of this for (Let key in rawdiaSemana) { diaSemana.push({ ...rawdiaSemana[key], id: key }) }

  • what the answer to that get?

  • GET returns Firebase objects in ARRAY because the purpose of for(Let key in rawdiaSemana... transforms objects into array

  • Send me the answer so I can simulate your real situation

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.