I am trying to access the users via redux
const mapStateToProps = state => ({
user: state.user.userdata
})
and when I do
console.log(this.props.user)
I get an array of two objects data and status
data: Array(2)
0: {id: 1, name: "kayondo"}
1: {id: 2, name: "syphat"}
length: 2
__proto__: Array(0)
status: 200
but when i try to map through the data key by
this.props.user.data.map(x => (<div>{x.name}</div>}
i get an error undefined in the console
? How can I solve this
console.log(this.props.user.data)? What is the full error message from the console? - Code-Apprenticethis.props.useritself an array, or are you just referring todata? It's tough to tell the entire data structure from what you posted. - Chris B.this.props.user.datadoesn't exist until after the api call is resolved. If this is the case you need a conditional renderconst { data } = this.props.user; if (data && data.length) { // map here }- Aaron Ross