The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Redux: Fetching Data on Route Change

Redux: Fetching Data on Route Change

3:46
We will learn how to fire up an async request when the route changes.
Watch this lesson now
Avatar
egghead.io

We will learn how to fire up an async request when the route changes.

Avatar
sabha

Can we use onEnter hook from router rather than wrapping the component generated by connect with another component?

In reply to egghead.io
Avatar
Dan Abramov

Yeah, you can do it. I find lifecycle hooks more convenient, e.g. if fetching should be done when some props outside the URL change.

In reply to sabha
Avatar
Hang

Would this following achieve the same thing with the same performance as the componentDidUpdate part?
componentWillReceiveProps(nextProps) {
if(this.props.filter !== nextProps.filter) {
fetchTodos(nextProps.filter).then(todos => ...)
}
}

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?