StackpressGitHub

API reference

View Client Hooks

The client hooks from stackpress/view/client read server-provided request, response, config, session, and server props inside React views.

Import

import {
  useConfig,
  useRequest,
  useResponse,
  useServer,
  useSession
} from 'stackpress/view/client';

Hooks

HookReturnsUse It For
useRequest<I>()Request propsReading request data passed to the view.
useResponse<O>()Response propsReading results, status, errors, or response data.
useConfig<C>()Config propsReading shared config and view props.
useSession()Session propsReading the current signed-in user/session state.
useServer<C, I, O>()Full server propsReading config, request, response, and session together.

Example

import { useResponse } from 'stackpress/view/client';

type Article = { id: string; title: string };

export function Body() {
  const response = useResponse<Article[]>();
  const rows = response.results || [];
  return rows.map(row => <h2 key={row.id}>{row.title}</h2>);
}

This example reads route-prepared response results. The view does not query the database directly; it renders the response payload provided by the server.