question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Rendered fewer hooks than expected" upon deletion of todo list item

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
staltzcommented, Nov 13, 2018

Right, so it was multiple calls to useMemo that were causing this. I had my attention on useState, and that one was nicely following the hook rules. A bit quirky, but it indeed works with an <ItemProf> component: https://codesandbox.io/s/mn73v8yr8

1reaction
sebmarkbagecommented, Nov 13, 2018

You’re calling useMemoizedProfunctorState inside promap which 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 promap to usePromap or something.

Ultimately this becomes a problem because you’re calling promap in a loop inside of List which is against another rule. Really, this is why the rule about only calling custom hooks inside other custom hooks exists.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found