hydrogen/packages/hydrogen/src/foundation/useServerState/README.md
2021-11-09 18:20:09 -08:00

1.5 KiB

The useServerState hook allows you to manage server state when using Hydrogen as a React Server Component framework.

Return value

The useServerState hook returns an object with the following keys:

Key Description
serverState The current server state.
setServerState A function used to modify server state.
pending Whether a transition is pending.

Example code

// For convenience, `setServerState` accepts arguments in the following ways:

// Update a top-level state property based on key
setServerState(key, value);

// Spread a new value object onto existing state
setServerState(newValue);

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