Ask Your Question
4

Why isn't the Nextjs state updating when the route is changed?

asked 2023-06-23 05:07:59 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-23 05:11:01 +0000

lakamha gravatar image

The Nextjs state is not updating when the route is changed because Nextjs uses server-side rendering and client-side rendering. When the route changes, the client-side rendering takes over but the state is not carried over from the server-side rendering. Therefore, if you want to update the state when the route changes, you need to use a React hook or a global state management library such as Redux or MobX.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-23 05:07:59 +0000

Seen: 12 times

Last updated: Jun 23 '23