onSearchStateChange trigger by defaultRefinement on RefinementList?

I am using react-instantsearch and it’s fantastic, seriously great job on it.

I have a question with the refinementsList connector, though.

I am applying default refinements to the refinementsList and I’d like to prevent refinements that don’t apply from being set as defaults.

For example, I have 3 transaction status: open, pending, closed.
My defaults are open and pending. Those are applied fine.

Though what if the person doesn’t have any pending transactions? It’ll say that there are no results.

I’d like to run a check on the default refinements prior to actually applying them to prevent non-applicable filters from being applied.

Edit-

So I was remembering my problem wrong.

Providing defaultRefinement will do what I was looking for but it does not trigger onSearchStateChange. Also, it still applies non-applicable filters.

I am trying to persist our filters into sessionStorage and it works great but the defaultRefinements aren’t being initially set.

I’m able to look at the Configure widget and get theSearchState, console.log it and see that the currentRefinements have been set.

How can I get defaultRefinement to trigger onSearchStateChanged?

Hi @peter4,

To answer your last question about defaultRefinement & onSearchStateChange - there is no way to trigger the callback from a default refinement. This is how React InstantSearch works.

Depending on your use case you could use the control mode of React InstantSearch. This mode lets you use the searchState directly to drive the state of the search. You can set your refinements directly on the state object rather than inside the defaultRefinement. The state will always be in sync, then you can persist it somewhere.

Hope that helps!