0

New to React, building a search app where the URL is built up based on search term entered and subsequent filters that are selected. I am updating the query string, not the path, based on search term and selections made. (e.g /?term=movies&selections=action,adventure) I am manually pushing these changes to the query string via browserHistory.push() in Action Creators. I'm not sure of the right pattern to follow to hydrate application state in response to these updates.

I can check query string params in componentWillMount(), on first render to render initial state, and that works fine, but when the browsers back/forward buttons are used I am not sure of the best pattern to follow to rebuild the state.

I am using the following modules on top of React: react-redux react-router react-router-redux

Advice appreciated thanks.

1 Answer 1

1

You need to check query in componentWillReceiveProps callback. Something like this:

componentWillReceiveProps(nextProps) {
  if (!_.isEqual(this.props.location.query, nextProps.location.query) {
     this.fetchDataFromServer(nextProps.location.query);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.