useEffect callbacks are not invoked for subsequent tests if there are more than one useEffect hooks
See original GitHub issueIf 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >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
Hi @MrCreeper1008 ,
Thanks a lot for reporting this. I’ll look into it.
ok I’ll give it a try. Thank you!