Props not loading before Render?

2Responses

Write your response…

like @topey said i am using something like

componentDidMount() { if(!this.props.user) { //fetch or dispatch } }

Write a reply...

Sounds like the prop is asynchronous? In that case I would usually put a check in your render method to exit early when this prop is not set then check it in the componentWillReceiveProps lifecycle event.

@topey So I tried putting an if else in there. and use componentWillReceiveProps to update state and but it doesn't seem in be firing.

And I get this.state.user is null when I refresh...

Write a reply...

Join a friendly and inclusive Q&A network for coders

  • 🖥Pick the technologies you like & read great content through your feed.
  • 💬Ask a question when you want to learn more about anything.
  • 🚀Share what you know & build your portfolio.
Sign up nowLearn more

loading ...