Skip to content

fix: correctly instantiate new API client if options change #25

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

Merged
merged 1 commit into from
May 19, 2022

Conversation

mxlje
Copy link
Contributor

@mxlje mxlje commented May 9, 2022

before this change a new client would not be instantiated when some options change, as useMemo doesn’t deep compare the values in the dependencies array. The workaround to use state for it didn’t actually work.

Also useMemo is meant to only be used as a performance improvement, which in this case is not enough because rely on the internal state of the API client so we don’t want to recreate it unless its options change.

Instead of useMemo we now use a deep compare effect which correctly compares the props, and then store the client as ref.

before this change a new client would not be instantiated when some
options change, as useMemo doesn’t deep compare the values in the
dependencies array. The workaround to use state for it didn’t actually
work.

Also useMemo is meant to only be used as a performance improvement,
which in this case is not enough because rely on the internal state of
the API client so we don’t want to recreate it unless its options
change.
Copy link
Contributor

@missinglink missinglink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@orangejulius
Copy link
Contributor

Great, I can see where we'll need this soon :)

I tested this out locally with the Geocode Earth website, and everything appears to work fine. Anything else to do before this is merged?

@mxlje mxlje merged commit 9f7d82b into main May 19, 2022
@mxlje mxlje deleted the fix/autocomplete-memoization branch May 19, 2022 13:29
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

Successfully merging this pull request may close these issues.

3 participants