Skip to content

Anyway to clear client cache using hooks? #5315

Answered by francoischalifour
cjbland asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @cjbland – we've worked on the last Hook to support caching and other top-level APIs. It looks like this:

function Search() {
  const { refresh } = useInstantSearch();

  return (
    <div>
      <button
        onClick={() => {
          refresh();
        }}
      >
        Refresh
      </button>
    </div>
  );
}

function App(props) {
  return (
    <InstantSearch {...props}>
      <Search />
    </InstantSearch>
  );
}

Here's a sandbox that implements useSearchCache().

See previous solution

For now, you can use useConnector() to retrieve the underlying InstantSearch.js API and expose it in React.

function connectSearchCache(renderFn, unmountFn = () => {}) {
  return (widgetParams)

Replies: 0 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@uncvrd
Comment options

@cjbland
Comment options

@francoischalifour
Comment options

@cjbland
Comment options

@Haroenv
Comment options

Answer selected by dhayab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Library: React InstantSearch ≥ 7 Issues in any of the react-instantsearch@7 packages (formerly named react-instantsearch-hooks)
4 participants