My App
BoardKitFrontend

useBoard

Load board data and pages from the API

useBoard fetches board data and pages from the REST API and syncs them into the BoardStore.

Signature

function useBoard(boardId: string): UseBoardResult;

Return Type

interface UseBoardResult {
    board: Board | null;
    pages: Page[];
    loading: boolean;
    error: string | null;
    reload: () => void;
}
PropertyDescription
boardThe loaded board object, or null while loading
pagesArray of pages belonging to the board
loadingtrue while the initial fetch is in progress
errorError message if the fetch failed, or null
reloadFunction to re-fetch the board data

Usage

import { useBoard } from '@hfu.digital/boardkit-react';

function BoardHeader({ boardId }: { boardId: string }) {
    const { board, pages, loading, error, reload } = useBoard(boardId);

    if (loading) return <p>Loading board...</p>;
    if (error) return <p>Error: {error} <button onClick={reload}>Retry</button></p>;

    return (
        <div>
            <h1>{board?.name}</h1>
            <p>{pages.length} pages</p>
        </div>
    );
}

Behavior

  1. On mount (and when boardId changes), fetches GET {apiUrl}/boards/{boardId}
  2. Sends Authorization: Bearer {authToken} if configured
  3. Populates the BoardStore with board data, pages, and sets the first page as active
  4. Subscribes to the board and pages store slices for reactive updates
  5. Re-renders when the store data changes (e.g., from collaboration updates)

On this page