Files
kandev/apps/web/hooks/use-board-snapshot.ts
T
2026-01-14 01:42:12 +00:00

20 lines
592 B
TypeScript

import { useEffect } from 'react';
import { fetchBoardSnapshot } from '@/lib/http';
import { snapshotToState } from '@/lib/ssr/mapper';
import { useAppStoreApi } from '@/components/state-provider';
export function useBoardSnapshot(boardId: string | null) {
const store = useAppStoreApi();
useEffect(() => {
if (!boardId) return;
fetchBoardSnapshot(boardId, { cache: 'no-store' })
.then((snapshot) => {
store.getState().hydrate(snapshotToState(snapshot));
})
.catch(() => {
// Ignore snapshot errors for now.
});
}, [boardId, store]);
}