React has detected a change in the order of Hooks called by Component.
See original GitHub issueRelated to the experiment of moving to Recoil, we’re seeing the above error message next to a Cannot assign to read only property
error message. What we’re doing is basically this:
const setState = useSetRecoilState(someAtomWithMutability)
useEffect(() => {
setState(s => {
s.close()
return null
})
}, [])
The atom is mutable and s.close() is mutating in some way. That seems to cause issues.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 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 ...
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 >Invalid Hook Call Warning
Hooks can only be called inside the body of a function component. There are three common reasons you might be seeing it: You...
Read more >react has detected a change in the order of hooks called - ...
This solves the error because we have to ensure that React hooks are called in the same order each time a component renders....
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 FreeTop 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
Top GitHub Comments
Assuming
s
is some kind of connnection or short lived object, I don’t think it’s a good idea to put that directly in recoil state. I would instead have an external object that managess
, and then store whatever datas
produces in recoil state.A note for anyone else who encounters ‘React has detected a change in the order of Hooks’: You will get this error when you accidentally use a React hook inside of Recoil code (such as in selector
get
implementation). It’s easy to inadvertently useuseRecoilValue(otherValue)
when you should be doingget(otherValue)
. The linter should be picking this up, but mine isn’t.