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
? How can I solve this
try it with
this.props.user.map(x => (<div>{x.name}</div>)
You aren't using the right syntax to map. Try using this one:
this.props.user.data.map(x => (<div>{x.name}</div>));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.