React has detected a change in the order of Hooks called by Root
See original GitHub issue
I’m using Next.js, when I navigated to another page, this error occurred
this is the target page code
const count = signal(0);
function Counter() {
return <button onClick={() => count.value++}>Value: {count.value}</button>;
}
export default Counter;
- next: 12.2.5
- react: 18.2.0
- signals-react: 1.0.2
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
"React has detected a change in the order of Hooks" but ...
I ran into this same error message in a component I was writing due to use of short-circuiting logic. This resulted in an...
Read more >How to overcome warning 'React has detected a change in ...
A look at a functional component that under non-obvious circumstances triggers this React Hooks warning.
Read more >React has detected a change in the order of Hooks called by ...
I see following error when I render a list. There are no if/else in the component which usually lead to such problem.
Read more >react has detected a change in the order of hooks called - You ...
Hooks always need to be called in the same order (so adding new hooks conditionally is not allowed). Your code is breaking this...
Read more >React has detected a change in the order of Hooks" but Hooks ...
The problem is that you're calling Event.Event() directly, even though it is a react component. That causes react to treat the hook calls...
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
For what it’s worth, I’ve come to the conclusion that this method of injecting useReducer into the current dispatcher can’t possibly work reliably and I’ve migrated legend-state away from it. We were seeing this bug in Next.js and users saw a similar bug in Expo Router, and in some Framer-Motion animations it was crashing as elements unmounted. After a lot of debugging I was not able to find a reliable solution. That combined with the React team telling us not to do it and that it would break soon made it seem untenable.
I hope you’re able to find a solution! But if not I hope I can save you some time knowing that it didn’t work for us.
Fixed by #219