My App
BoardKitFrontend

BoardKitProvider

Context provider setup with configuration and theming

BoardKitProvider is the root context provider for BoardKit. It instantiates the BoardStore, Canvas2DRenderer, and ToolRegistry and makes them available to all child hooks and components.

Usage

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

function App() {
    return (
        <BoardKitProvider
            config={{
                apiUrl: '/api',
                wsUrl: 'ws://localhost:3000/board',
                authToken: 'your-jwt-token',
                theme: {
                    selectionColor: '#3b82f6',
                    handleColor: '#1d4ed8',
                },
            }}
        >
            <YourApp />
        </BoardKitProvider>
    );
}

BoardKitConfig

interface BoardKitConfig {
    apiUrl: string;
    wsUrl?: string;
    authToken?: string;
    theme?: Partial<BoardKitTheme>;
}
PropertyRequiredDescription
apiUrlYesBase URL for the REST API (e.g., /api or https://api.example.com)
wsUrlNoWebSocket URL for realtime collaboration (e.g., ws://localhost:3000/board)
authTokenNoBearer token for authentication (sent with all API and WebSocket requests)
themeNoVisual customization options

BoardKitTheme

interface BoardKitTheme {
    selectionColor: string;
    handleColor: string;
    cursorLabelFont: string;
}
PropertyDescription
selectionColorColor of the selection box and selection highlights
handleColorColor of resize/rotation handles
cursorLabelFontFont used for remote cursor name labels

BoardKitProviderProps

interface BoardKitProviderProps {
    config: BoardKitConfig;
    children: React.ReactNode;
}

useBoardKit

Access the context value from any child component:

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

function MyComponent() {
    const { store, renderer, toolRegistry, config } = useBoardKit();
    // Direct access to the store, renderer, and tool registry
}
interface BoardKitContextValue {
    store: BoardStore;
    renderer: Canvas2DRenderer;
    toolRegistry: ToolRegistry;
    config: BoardKitConfig;
}

Throws an error if called outside of a BoardKitProvider.

Implementation Details

  • BoardStore, Canvas2DRenderer, and ToolRegistry are created once using useRef (stable across re-renders).
  • The ToolRegistry is initialized with all default tools via ToolRegistry.createDefault().
  • The renderer is cleaned up (.destroy()) when the provider unmounts.
  • The context value is memoized and only changes when config changes.

On this page