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

Rerender triggered three times when dependencies change #29

Open
dharkness opened this issue Apr 27, 2020 · 0 comments
Open

Rerender triggered three times when dependencies change #29

dharkness opened this issue Apr 27, 2020 · 0 comments

Comments

@dharkness
Copy link

This may be related to #24. Whenever I change the dependencies, I get three rerenders where I only expect to see two.

Expected:

  1. Change dependencies.
  2. Render with isLoading === true, data === null
  3. Render with isLoading === false, data === <new-result>

Actual:

  1. Change dependencies.
  2. Render with isLoading === false, data === <previous-result>
  3. Render with isLoading === true, data === <previous-result>
  4. Render with isLoading === false, data === <new-result>

I don't care so much about data containing the previous result, and changing just that to null with no additional changes would be bad. But why am I getting that first rerender which is a copy of the previous call result? I would expect calling the hook with changed dependencies to immediately return with isLoading === true.

To be clear, everything works okay. The downside is the additional no-op render due to the first result being identical to the previous result. I assume the fetch call has been made by that point, and yet the hook tells me it's not loading. Is there any way to avoid that (step 2 above)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant