UNPKG

vite-plugin-react-server

Version:
39 lines 1.35 kB
import type { RscHmrData } from "./createReactFetcher.js"; /** * React hook for RSC HMR (Hot Module Replacement). * * When a server component file changes, this hook calls your `refetch` function * to re-fetch the RSC stream. Combined with `startTransition`, this preserves * client component state while updating server-rendered content. * * @example * ```tsx * import { useRscHmr } from 'vite-plugin-react-server/utils'; * * function Shell({ data }) { * const [storeData, setStoreData] = useState(data); * * const refetch = useCallback((url: string) => { * startTransition(() => { * setStoreData(createReactFetcher({ url })); * }); * }, []); * * // Refetch RSC stream when server components change * useRscHmr(refetch); * * return <>{use(storeData)}</>; * } * ``` * * @param refetch - Function to call when server components change. * Receives the current pathname. Use `startTransition` inside for smooth updates. * @param options - Optional configuration */ export declare function useRscHmr(refetch: (url: string) => void, options?: { /** Whether to log HMR events. @default true in dev */ verbose?: boolean; /** Custom filter — return false to skip refetch for specific files */ filter?: (data: RscHmrData) => boolean; }): void; //# sourceMappingURL=useRscHmr.d.ts.map