#community-help

Switching Search Client Modes with react-instantsearch-dom

TLDR Zeyu asked about switching searchClient modes. Jason suggested re-instantiating Instantsearch.js and dynamically rendering widgets on button click.

Powered by Struct AI
5
4mo
Solved
Join the chat
May 24, 2023 (4 months ago)
Zeyu
Photo of md5-a7605b093448e06efb0a1c150153cad6
Zeyu
05:46 PM
I’m trying to use both normal search and vector search. A user can switch different “mode” when searching. However, I’m not sure how to switch between two searchClient by clicking a button. What is the best practice here?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:55 PM
You would have re-instantiate all of Instantsearch.js along with the search client when the button is clicked
05:55
Jason
05:55 PM
So you’d want to move all of the initialization code into a function, and call that function both on page load and also on button click
Zeyu
Photo of md5-a7605b093448e06efb0a1c150153cad6
Zeyu
06:15 PM
we are using react-instantsearch-dom,and we wish to click the button within SearchComponent
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:51 PM
It would be a similar concept - you would have to render the widgets dynamically and have them be re-rendered when the button is pressed, by may be attaching a variable as the react component’s key and changing this variables value when the button is pressed