Rerender triggered three times when dependencies change
dharkness opened this issue · 0 comments
This may be related to #24. Whenever I change the dependencies, I get three rerenders where I only expect to see two.
Expected:
- Change dependencies.
- Render with
isLoading === true, data === null
- Render with
isLoading === false, data === <new-result>
Actual:
- Change dependencies.
- Render with
isLoading === false, data === <previous-result>
- Render with
isLoading === true, data === <previous-result>
- 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)?