Skip to content

packages/core/src/lib/hooks/use-signal.ts

Read as Markdown

This is the source snapshot used to build these API details. View this revision on GitHub.

Back to reference

1 import { signal } from '../signals/graph.js';
2 import type { SignalOptions, WritableSignal } from '../signals/types.js';
3 import { useHookSlot } from './hook-slot.js';
4 
5 /**
6  * Creates one component-owned writable signal identity for a hook slot.
7  *
8  * @param initialValue - Value stored when this hook slot is first created.
9  * @param options - Equality comparison and optional diagnostic name. See {@link SignalOptions}.
10  * @returns A stable mount-owned writable signal. See {@link WritableSignal}.
11  *
12  * @see {@link SignalOptions}
13  * @see {@link WritableSignal}
14  */
15 export function useSignal<T>(
16   initialValue: T,
17   options?: SignalOptions<T>,
18 ): WritableSignal<T> {
19   return useHookSlot(
20     'signal',
21     () => signal(initialValue, options),
22   ).value;
23 }
24 

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.