Calling a function in a component when a query parameter changes
See original GitHub issueRight now I’m working on moving some of our component state into query parameters so that pages are bookmarkable and other components can cleanly change the values.
It looks like react-router will call .render
when a query parameter changes, but it’s not clear how to tell which part of the URL / which query parameter changed, and the work I’m doing is outside of .render, in an onChange or componentDidUpdate lifecycle method.
Is there a clean way of implementing this? It seems like I either need to:
- Duplicate the query parameters in the component’s state so I know when they change
- Or pass the query parameters down my view hierarchy from the router as a prop
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Calling a function in a component when a query parameter ...
It looks like react-router will call .render when a query parameter changes, but it's not clear how to tell which part of the...
Read more >Is there a react component event for when url query string ...
Your component will get query params in this.props.location.search and when query params change componentWillReceiveProps will fire.
Read more >Syncing query parameters with react state - Inkoop
We will be using it inside our react components and will call this function whenever we want to update our query parameters.
Read more >Using React Hooks to sync your component state and the URL ...
First, we import the hooks useState and useCallback from React and the functions getQueryStringValue and setQueryStringValue we defined before ...
Read more >Query Parameters - Routing - Ember Guides
Query parameters are optional key-value pairs that appear to the right of the ? in a URL. For example, the following URL has...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ryanflorence I believe you meant:
If I need that info I pass the params/query down my route view hierarchy and let react’s lifecycle hooks help me out.
Now its available here on every component:
edit thanks @abergs