Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show line where hook that changed is used (feature request) #191

Open
DamianPereira opened this issue Apr 27, 2021 · 3 comments
Open

Show line where hook that changed is used (feature request) #191

DamianPereira opened this issue Apr 27, 2021 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DamianPereira
Copy link

I currently have a very big hook, with dozens of useStates, lots of them have empty arrays which trigger unncesary re-renders. But I don't know which is the one doing it each time wdyr logs it's output. I get:

Re-rendered because of hook changes: 
[hook useState result]
...diff

When would be very useful for me is:

Re-rendered because of hook changes:
[hook useState result] (someRandomHook.ts:34)
...diff

Knowing which hook is changing would be useful, specially in nested hooks scenarios, for example I have a hook which uses a hook, and that internal one has state, but wdyr does not even specify which hook is that useState from (I guess react makes no distinction, it only cares about hook declaration order, so not sure how possible would this feature request be.)

@vzaidman
Copy link
Collaborator

it's probably possible to do:

  1. throw a new Error
  2. catch the error
  3. use the call stack to find the line of the hook

if anybody wants to try implementing it, this could be nice indeed.

@vzaidman vzaidman added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Apr 28, 2021
@DouglasPds
Copy link

Hello, I will try to implement this.

@erictehyc
Copy link

Hello, will be interested in this feature too.
May I know if it will be merged and how could we use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants