Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 4x 6x 6x 6x 7x 2x 5x 1x 4x 4x | import { applySignal } from './apply-signal';
/** @typedef {import('./apply-signal').RouteSignal} RouteSignal */
/** @typedef {import('./create-use-signal-effect').UseEffectHook} UseEffectHook */
/** @typedef {import('./create-use-signal-effect').UseRefHook} UseRefHook */
/** @typedef {import('./create-use-signal-effect').UseTaoContextHook} UseTaoContextHook */
/** @typedef {import('./create-use-signal-effect').ApplySignalFn} ApplySignalFn */
/**
* The hook a `createUseRouteSignal` factory returns: applies each new
* identity of an explicitly-passed route-entry signal to the ambient
* Kernel exactly once.
*
* @typedef {(signal: RouteSignal | null | undefined) => void} UseRouteSignalHook
*/
/**
* Dependencies injected into `createUseRouteSignal`.
*
* @typedef {object} UseRouteSignalDeps
* @property {UseEffectHook} useEffect
* @property {UseRefHook} useRef
* @property {UseTaoContextHook} useTaoContext
* @property {ApplySignalFn} [apply]
*/
/**
* Factory for a React hook that applies an explicit route-entry signal
* (Next.js pages, RSC props, etc. — no host loader data API).
*
* @param {UseRouteSignalDeps} deps
* @returns {UseRouteSignalHook}
*/
export function createUseRouteSignal({
useEffect,
useRef,
useTaoContext,
apply = applySignal,
}) {
return function useRouteSignal(signal) {
const TAO = useTaoContext();
const applied = useRef(null);
useEffect(() => {
if (signal == null) {
return;
}
if (applied.current === signal) {
return;
}
applied.current = signal;
apply(TAO, signal);
}, [TAO, signal]);
};
}
|