Skip to content

Instantly share code, notes, and snippets.

@gregfenton
Created March 8, 2024 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregfenton/f29d6aea5ff186d019203527473481a0 to your computer and use it in GitHub Desktop.
Save gregfenton/f29d6aea5ff186d019203527473481a0 to your computer and use it in GitHub Desktop.
Algolia react-instantsearch code not working correctly
<InstantSearch
indexName={ALGOLIA_INDEX_PROJECT}
searchClient={searchClient}
routing={routing}
future={{
preserveSharedStateOnUnmount: true,
}}
onStateChange={({uiState, setUiState}) => {
if (firstRender.current) {
firstRender.current = false;
if (myUiStateCache) {
console.log(`firstRender USE CACHE:`, myUiStateCache);
setUiState({...myUiStateCache});
} else {
console.log(`firstRender USE INITIAL VALUES:`, uiState);
setUiState(uiState);
}
} else {
updateMyUiStateCache(uiState);
setUiState(uiState);
}
}}
>
<ProjectListResults />
</InstantSearch>
@gregfenton
Copy link
Author

Code snippet to go with the issue posted on Algolia Community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment