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.

useEffect callbacks are not invoked for subsequent tests if there are more than one useEffect hooks

See original GitHub issue

If a component has more than one useEffect hook, the callback will be invoked only for the very first test in a describe block.

A very simple reproduction:

function Component() {
  useEffect(() => {
    console.log('test 1');
  }, []);

  useEffect(() => {
    console.log('test 2');
  }, []);

  return null;
}

describe('test', () => {
  it('useEffect works', () => {
    shallow(<Component />);
  });

  it('useEffect does not work', () => {
    shallow(<Component />);
  });
})

Note that if I remove t he deps array everything will be back to normal.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeborozdincommented, Apr 10, 2020

Hi @MrCreeper1008 ,

Thanks a lot for reporting this. I’ll look into it.

0reactions
kennethnymcommented, Apr 16, 2020

ok I’ll give it a try. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Hooks: useEffect() is called twice even if an empty array ...
The component is being forced to unmount and remount on its initial render. This could be something like a "key" change happening higher...
Read more >
useEffect callback never called · Issue #17066 · facebook/react
I want to report a bug. My problem is that the callback function I pass to useEffect() is never called in my app....
Read more >
The last guide to the useEffect Hook you'll ever need
Understanding how the useEffect Hook works, and why it requires a wholesale shift in mindset, is essential to writing modern React code.
Read more >
Hooks API Reference - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This page...
Read more >
A Simple Explanation of React.useEffect() - Dmitri Pavlutin
A functional React component uses props and/or state to calculate the output. If the functional component makes calculations that don't target ...
Read more >

github_iconTop Related Medium Post

No results found

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