简体   繁体   中英

React state updating but not mapping

I'm using redux to manage my state and I can see that it is updating correctly judging from devtools and I can also console log it with this.props.myobj .

However if I try to map through it with this.props.myobj then I get TypeError: Cannot read property 'map' of undefined

If i try to map it with this.state.myobj then it remains blank.

Just to reiterate I'm using redux, mapstatetoprops, and can see that the state both in redux and in the component is being updated and set correctly.

Maybe this.props.obj is not available in the first render. Try { this.props.obj && this.props.obj.map(()=>{}) }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM