#community-help

Fetching Search Results as an Array in React

TLDR Yusuf needed help on getting search results as an array in React. Jason suggested using the typesense-js API to call the search endpoint. The solution worked for Yusuf.

Powered by Struct AI

1

3
1mo
Solved
Join the chat
Aug 23, 2023 (1 month ago)
Yusuf
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Yusuf
08:23 PM
Jason and typesense community, this may be a basic question, but I'm having trouble figuring out how to get the search results as an array of objects in React so that I can pass it in as props to the component that renders them

I don't want to use the <Hits/> component, because I already have my own custom component for rendering the results. I just want the user to be able to edit some filters (stored as state variables), and have that re-fetch the search results from my Typesense cluster, and then pass in those results to the rendering component like so: <RenderingComponent searchResults={searchResults} />.

how can I do this in React?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:46 PM
You want to use typesense-js and make an API call to the search endpoint: https://typesense.org/docs/0.25.0/api/search.html
Aug 24, 2023 (1 month ago)
Yusuf
Photo of md5-faf0fdba0b6739a6706f05c15b6738c6
Yusuf
07:25 PM
thank you Jason, that did the trick!

1