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

Cache key not updating on change #952

Closed
sallomendo opened this issue Feb 23, 2022 · 6 comments
Closed

Cache key not updating on change #952

sallomendo opened this issue Feb 23, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@sallomendo
Copy link

Bug Report

Describe the Bug

fetchPredictions callback is not updating when cache or cacheKey changes.

How to Reproduce

When the cache key is stateful, the window storage key doesn't change.

const [countryCode, setCountryCode] = useState("US")

const autocomplete = usePlacesAutocomplete({
    cacheKey: countryCode
});

Expected Behavior

The cache and cache key should change when you pass a different value.

Your Environment

  • Device: MacBook Pro
  • OS: macOS
  • Browser: Chrome
  • Version: 1.11.0

Additional Information

I think we need to add cache and cacheKey as a dependency to the useCallback hook here https://github.com/wellyshen/use-places-autocomplete/blob/master/src/usePlacesAutocomplete.ts#L155

@wellyshen
Copy link
Owner

wellyshen commented Mar 6, 2022

@sallomendo Ask a DX question. Should we need to remove the previously cached data when the key is updated?

@wellyshen wellyshen added the enhancement New feature or request label Mar 6, 2022
@sallomendo
Copy link
Author

@wellyshen I don’t think so, we can use the clearCache function inside a useEffect hook, I think we should leave that to the dev.

@wellyshen
Copy link
Owner

@sallomendo Sorry quite busy recently, would you mind to give me a PR for this issue?

@wellyshen
Copy link
Owner

@sallomendo This issue has been fixed in the latest version.

@sallomendo
Copy link
Author

@wellyshen thanks for working on this, I will close the pr I created for this.

@wellyshen
Copy link
Owner

@sallomendo Sorry I didn't note that, thank you!

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

No branches or pull requests

2 participants