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.

Allow renaming useEffect to useWhatChanged, and adding 3rd arg for dependencies label

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
devinrhode2commented, Sep 14, 2020

Actually, this idea could be implemented in user-land, outside your package source, like so:

import {useEffect} from 'react';
import { useWhatChanged as core_useWhatChanged } from '@simbathesailor/use-what-changed';

const useWhatChanged = (effectCallback, deps, depLabels) => {
  useEffect(effectCallback, deps);
  core_useWhatChanged(deps, depLabels);
};

// inside react component:
useWhatChanged(() => {
  console.log(bar)
}, [bar], 'bar');
0reactions
simbathesailorcommented, Mar 30, 2021

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.

Read more comments on GitHub >

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

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