import type { SearchState } from 'react-instantsearch-core' ; import type { InstantSearchProps } from 'react-instantsearch-dom' ; import { findResultsState } from 'react-instantsearch-dom/server' ; import { getSearchClient } from '@/hooks/useSearchClient' ; export type GetResultsStateParams = { component : React . ComponentType < Pick < InstantSearchProps , 'indexName' | 'resultsState' | 'searchClient' | 'searchState' | 'widgetsCollector' > > ; searchState : SearchState ; appId : string ; searchApiKey : string ; indexName : string ; [ index ] : any ; } ; export async function getResultsState ( { component , searchState , appId , searchApiKey , indexName , ... customProps } ) { const searchClient = getSearchClient ( appId , searchApiKey ) ; const firstResultsState = await findResultsState ( component , { ... customProps , searchClient , indexName , searchState , } ) ; let resultsState = await findResultsState ( component , { ... customProps , searchClient , indexName , searchState , resultsState : firstResultsState , } ) ; resultsState = JSON . parse ( JSON . stringify ( resultsState ) ) ; return resultsState ; }