Skip to content
Discussion options

You must be logged in to vote

Hi,

Are you calling router.replace or any method under the router, while rendering? as in:

const App = () => {
  if (condition) router.replace()
 
 return <div />
}

That'll lead to disaster, because it is setting state as your render, which means the render is not pure, which means you are potentially batching more state updates, while trying to reflect an state update.

The root cause being that, router methods (replace, push, etc) are now using React's state management, useReducer. You can install redux-devTools and see the actions being dispatched! (Because the Next.js team con…

Replies: 3 comments 13 replies

Comment options

You must be logged in to vote
12 replies
@Reflex2468
Comment options

@bartoszhernas
Comment options

@pythonicode
Comment options

@bartoszhernas
Comment options

@heecheon92
Comment options

Answer selected by matallui
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@EthicalJobsJesse
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
9 participants