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
push
orreplace
methods to update the query within the state update function. - Use the
useEffect
hook with therouter.query
dependency 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
getInitialProps
method to do this. - If the issue persists, you can try using the
useRouter
hook to access the router object and its query directly in your component, rather than using therouter
object 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 13 times, 1 visits today)
Was this article helpful?
YesNo
Last modified: March 3, 2023