Skip to content

useRef

Read as Markdown

import { useRef, Text } from "@pibbl/core";

useRef(init?) is render-only and returns one stable PibblRef with a generic mutable current field for the component identity. Updating current does not schedule a render. Its normal hook slot lifetime ends when the component unmounts; do not use it to preserve state across a changed component identity.

function Counter() {
const renders = useRef(0);
renders.current = (renders.current ?? 0) + 1;
return <Text>{renders.current}</Text>;
}

Use useSignal for values that should schedule updates.

Hook: Creates a reference object, similar to React’s useRef.

useRef: <T>(init?: T) => PibblRef<T>

Related API: useRef, PibblRef.

  • init — The initial reference value

A reference with a current property containing the value

PibblRef

View source — packages/core/src/lib/hooks/use-ref.ts:20

Read the Authoring, signals, and lifecycle companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

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