Allow renaming useEffect to useWhatChanged, and adding 3rd arg for dependencies label
See original GitHub issueI was editing my stackoverflow answer pointing to this project, and realized there could be a much better api when you are not using the babel plugin
My idea is to allow developers to change this code:
useEffect(() => {
console.log(bar)
}, [bar]);
to this:
useWhatChanged(() => {
console.log(bar)
}, [bar], 'bar');
Please ignore this comment/imagine I removed it in an edit/deleted it:
When I was using useWhatChanged, I noticed once I remove the “bad” deps from my useEffect hook, things were still re-rendering, until I removed them from useWhatChanged
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Hooks API Reference - React
React guarantees that setState function identity is stable and won't change on re-renders. This is why it's safe to omit from the useEffect...
Read more >React useEffect including the missing dependency will break it
I think the missing dependency warning is shown because you're shadowing barObj from the state. Try using different argument name and avoid ...
Read more >Debug your Reactjs Hooks with ease !! | by Anil Chaudhary
With these large dependency array, I found it really difficult to debug and find out what is causing my useEffect to run again(...
Read more >The Guide to Learning React Hooks (Examples & Tutorials)
So let's do just that and update our examples to have a side effect that uses the new Hook useEffect . Let's add...
Read more >React useEffect() Hook: Basic Usage, When and How to Use It?
Let's come to the point and discuss today's topic, useEffect hook. ... of dependencies passed as the second argument to react useEffect.
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
Actually, this idea could be implemented in user-land, outside your package source, like so:
I have added the support to enable/disable logging via one time call or based on NODE_ENV key now. Although I have supported this configuration, I must recommend to use https://github.com/simbathesailor/babel-plugin-use-what-changed for better dev experience. Closing the ticket for now.