packages/core/src/lib/hooks/use-const.ts
This is the source snapshot used to build these API details. View this revision on GitHub.
1 import type { PibblComponent } from '../element/types.js';
2 import { untracked } from '../signals/graph.js';
3 import { useHookSlot, withHooksForbidden } from './hook-slot.js';
4
5 /**
6 * Creates one non-reactive value for the lifetime of a mounted hook slot.
7 *
8 * @param create - Initializer called once for this mounted hook slot.
9 * @returns The value retained by this hook slot.
10 *
11 * @see {@link PibblComponent}
12 */
13 export function useConst<T>(create: () => T): T {
14 return useHookSlot(
15 'const',
16 () => untracked(() => withHooksForbidden(
17 'Pibbl hooks cannot be called inside a useConst factory.',
18 create,
19 )),
20 ).value;
21 }
22
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.