Skip to content

Conversation

schettino
Copy link
Owner

Up to now, passing default request params to useResource as a dependency would make it store the last used values, so we could use it to make a deep comparison on every following update attempt to avoid unnecessary calls to the API. On low connections and in fast-changing params scenario though, updating the params before completing a request could make it to be cancelled, even in cases of a false-positive param update (user triggered an update without changing any value, making the deep comparison to fail, but the effect to run the clean up phase anyway).

To solve this, we make use of useState capability to bail out of rendering if the value to be updated is the same as the previous one. And thus use the current value as a dependency for the effect that does the actual call.

Although we've been supporting all versions of React that have included hooks, the bail out on useState is available only on 16.8+. Therefore, it's safer to call this a major and prevent impacting those who are using this utility, in a dangerous way.

@codecov-io
Copy link

codecov-io commented Apr 13, 2019

Codecov Report

Merging #3 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #3   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          73     76    +3     
  Branches       11     12    +1     
=====================================
+ Hits           73     76    +3
Impacted Files Coverage Δ
src/useResource.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70fe704...d825af9. Read the comment docs.

@schettino schettino merged commit 7a7da5c into master Apr 18, 2019
@schettino
Copy link
Owner Author

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@schettino schettino deleted the v2 branch June 16, 2019 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants