Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Clear all current refinements #3252

Closed
mellson opened this issue Jan 9, 2022 · 6 comments
Closed

Clear all current refinements #3252

mellson opened this issue Jan 9, 2022 · 6 comments

Comments

@mellson
Copy link

mellson commented Jan 9, 2022

馃悰 Bug description

I'm missing a way to clear all current refinements using the hooks api.
Maybe I'm missing something, but with useCurrentRefinements there's only an option to clear 1 refinement at a time, which will lead to a new search per refinement being cleared.

With the dom package it's possible to clear all refinements at once.

@Haroenv
Copy link
Contributor

Haroenv commented Jan 10, 2022

unlike the current major version, clearRefinements has its own connector:

import connectClearRefinements, {
  ClearRefinementsConnectorParams,
  ClearRefinementsWidgetDescription,
} from 'instantsearch.js/es/connectors/clear-refinements/connectClearRefinements';
import { useConnector } from 'react-instantsearch-hooks';

type UseClearRefinementsProps = ClearRefinementsConnectorParams;

function useClearRefinements(props: UseClearRefinementsProps) {
  return useConnector<
    ClearRefinementsConnectorParams,
    ClearRefinementsWidgetDescription
  >(connectClearRefinements, props);
}

Then you can use refine from the clear refinements connector

@mellson
Copy link
Author

mellson commented Jan 10, 2022

@Haroenv thanks, this worked great! Maybe not the right place to ask this, please direct me to where questions are more suitable if it's not here.

But I'm experiencing some extra round trips to Algolia after moving to the hooks API. For instance with the dom package I could have a structure like this:

<InstantSearch>
  <Configure />
  <SearchBox />
  <Stats />
  <RefinementList(s)... />
  <HitsPerPage />
</InstantSearch>

and this would be fine and only do one round trip to Algolia when I opened a page.

Now when I have a similar structure with the hooks API the same page open has 3 or 4 round trips to the Algolia servers.

One thing I'm seeing is that when I change the number of hits to fetch using useHitsPerPage the initial couple of round trips to the servers just have the default number of hits in them.

What would be the right way to get a custom number of hits on the first round trip using the hooks api?

@francoischalifour
Copy link
Member

@mellson Thanks for all these reports on the Hooks package. Could you please create a sandbox that shows these round trips to the Algolia servers? (If you don't mind, a new GitHub issue would be appropriate.)

@mellson
Copy link
Author

mellson commented Jan 11, 2022

@francoischalifour thanks, I'll create a new issue if I can recreate this in a sandbox.

@mellson mellson closed this as completed Jan 11, 2022
Haroenv added a commit that referenced this issue Jan 11, 2022
* feat(hooks): implement useClearRefinements

FX-737
#3252

* Update examples/hooks/components/ClearRefinements.tsx

Co-authored-by: Fran莽ois Chalifour <francoischalifour@users.noreply.github.com>

Co-authored-by: Fran莽ois Chalifour <francoischalifour@users.noreply.github.com>
@mellson
Copy link
Author

mellson commented Jan 14, 2022

@francoischalifour just a quick update, I think it was a problem with concurrent mode in the version of React 18 I was using: 18.0.0-rc.0 upgrading to the latest version 18.0.0-rc.0-next-c09596cc6-20220112 solves it. Now I can't recreate this behaviour any more. Thanks for your help.

@francoischalifour
Copy link
Member

Sounds good鈥攖hanks for letting us know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants