Skip to main content

useServerProps

The useServerProps hook allows you to manage the server props passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.

Example code

// `setServerProps` accepts arguments in the following ways:

// Update a top-level server component prop based on key
setServerProps(key, value);

// Spread a new value object onto existing props
setServerProps(newValue);

// Provide a callback function to update the state completely
setServerProps((previousProps) => object);

Return value

The useServerProps hook returns an object with the following keys:

KeyDescription
serverPropsThe current server props.
setServerPropsA function used to modify server props.
pendingWhether a transition is pending.