"Rendered fewer hooks than expected" upon deletion of todo list item
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
Codesandbox: https://codesandbox.io/s/1vy8n91y7 add a few todo items to the list, then press one of the red X buttons to delete one of them.
What is the expected behavior?
The todo item gets deleted.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.7.0-alpha.0 using hooks.
TL;DR of useProfunctorState hook: underneath it uses useState and useMemo. For each useProfunctorState call, there is only one call of useState. Children components that use promap don’t have their own real “setState”, instead they all share the setState from the top-level component.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to fix React Error: Rendered fewer hooks than expected
First, double check that you're not calling hooks within a conditional statement. The Hooks documentation makes clear that we are to use hooks...
Read more >Rendered fewer hooks than expected. when using useState ...
Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement. My code: const [mouseOver, setMouseOver] ...
Read more >Fix - Rendered fewer hooks than expected in React
Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement. In this article, we will see why...
Read more >Rendered fewer hooks than expected. This may be caused by ...
Today i have just met this error, i fixed it by change the position of hook: useEffect() from middle to header of function....
Read more >Rendered fewer hooks than expected error in React
The error "Rendered fewer hooks than expected. This may be caused by an accidental early return statement" occurs when we use a hook...
Read more >
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

Right, so it was multiple calls to
useMemothat were causing this. I had my attention onuseState, and that one was nicely following the hook rules. A bit quirky, but it indeed works with an<ItemProf>component: https://codesandbox.io/s/mn73v8yr8You’re calling
useMemoizedProfunctorStateinsidepromapwhich is a regular function instead of a hook - which against the “rules of hooks”.Our lint rule would’ve caught that. Although I’m not sure if it would if you renamed
promaptousePromapor something.Ultimately this becomes a problem because you’re calling
promapin a loop inside ofListwhich is against another rule. Really, this is why the rule about only calling custom hooks inside other custom hooks exists.