It looks like you are trying to update the state of your Next.js app when the router query changes, but this is causing an infinite loop. Here are a few things you can try to fix this issue:
- Make sure that you are not accidentally causing the query to change in your state update function. This can happen if you are using the router’s
replacemethods to update the query within the state update function.
- Use the
useEffecthook with the
router.querydependency to update the state only when the query changes. This will ensure that the state update function is not called unnecessarily.
- If you need to update the state based on the initial query when the component mounts, you can use the
getInitialPropsmethod to do this.
- If the issue persists, you can try using the
useRouterhook to access the router object and its query directly in your component, rather than using the
routerobject passed as a prop.
I hope these suggestions help! Let me know if you have any other questions or if there’s anything else I can do to assist.
(Visited 1 times, 1 visits today)
Was this article helpful?
Last modified: March 3, 2023