1/**2 * Preact binding for the storage-container fork guard: the live fork state,3 * for apps that render their own surface in place of the framework's default4 * fork notice.5 *6 * @module7 */89import { useEffect, useState } from "preact/hooks";10import {11 type StorageForkGuard,12 storageForkGuard,13 type StorageForkState,14} from "../runtime/storage-fork.ts";1516export type { StorageForkState } from "../runtime/storage-fork.ts";1718/** The guard surface a component observes; defaults to the shared guard. */19export type StorageForkSurface = Pick<StorageForkGuard, "getState" | "subscribe">;2021/**22 * Subscribes a Preact component to the storage-container fork guard, so apps23 * can render their own install warning or fork notice in place of the24 * framework default (suppress the default with `pwa: { forkNotice: "none" }`25 * in `defineLofiApp`).26 *27 * @example28 * ```tsx29 * import { useStorageFork } from "@nzip/lofi/preact";30 *31 * const fork = useStorageFork();32 * if (fork.state === "fork-detected") return <ForkNotice message={fork.message} />;33 * ```34 *35 * @param guard The guard to observe; defaults to the package-wide guard.36 * @returns The current fork state, kept live via subscription.37 */38export function useStorageFork(guard: StorageForkSurface = storageForkGuard): StorageForkState {39 const [state, setState] = useState<StorageForkState>(guard.getState());40 useEffect(() => guard.subscribe(setState), [guard]);41 return state;42}