packages/core/src/lib/hooks/use-ref.ts
This is the source snapshot used to build these API details. View this revision on GitHub.
1 import { useHookSlot } from './hook-slot.js';
2
3 /**
4 * A stable mutable container whose current value does not itself schedule rendering.
5 *
6 * @see {@link useRef}
7 */
8 export interface PibblRef<T> {
9 /** Mutable value retained by the ref container. See {@link PibblRef}. */
10 current: T | undefined;
11 }
12
13 /**
14 * Hook: Creates a reference object, similar to React's useRef.
15 * @param init The initial reference value
16 * @returns A reference with a `current` property containing the value
17 *
18 * @see {@link PibblRef}
19 */
20 export function useRef<T>(init?: T): PibblRef<T> {
21 return useHookSlot('ref', () => ({ current: init })).value;
22 }
23
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.