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 }) }
– Pedro Henrique Cndido Ferreira
what the answer to that get?
– Pedro Henrique Cndido Ferreira
GET returns Firebase objects in ARRAY because the purpose of for(Let key in rawdiaSemana... transforms objects into array
– Henrique Coletta
Send me the answer so I can simulate your real situation
– Pedro Henrique Cndido Ferreira