API Reference / React InstantSearch Hooks / getServerState()
Signature
const serverState = await getServerState(children: ReactNode)
Import
1
import { getServerState } from 'react-instantsearch-hooks-server';

About this function

getServerState() is the function that retrieves the server state to pass to <InstantSearchSSRProvider>.

This function is available from the companion react-instantsearch-hooks-server package.

Examples

1
2
3
import { getServerState } from 'react-instantsearch-hooks-server';

const serverState = await getServerState(<App />);

Check the server-side rendering example for full markup.

Parameters

children
type: React.ReactNode

The part of the app that renders <InstantSearch>.

1
const serverState = await getServerState(<App />);

Returns
Promise

serverState
type: InstantSearchServerState

The server state to pass to <InstantSearchSSRProvider>.

1
2
3
4
5
6
7
8
9
10
type InitialResult = {
  state: SearchParameters;
  results: SearchResults;
};

type InitialResults = Record<string, InitialResult>;

type InstantSearchServerState = {
  initialResults: InitialResults;
};
Did you find this page helpful?
React InstantSearch Hooks v6