# useRef

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

`useRef(init?)` is render-only and returns one stable [`PibblRef`](/reference/types/canvas-runtime/#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.

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

Use [`useSignal`](/reference/hooks/use-signal/) for values that should schedule updates.

## API details from source

<span id="api-useRef"></span>

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

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

Related API: [useRef](/reference/hooks/use-ref/), [PibblRef](/reference/types/canvas-runtime/#pibblref).

### Parameters

- **`init`** — The initial reference value

### Returns

A reference with a `current` property containing the value

### See also

[PibblRef](/reference/types/canvas-runtime/#pibblref)

[View source — packages/core/src/lib/hooks/use-ref.ts:20](/source/packages/core/src/lib/hooks/use-ref-ts/#L20)

## Implementation guidance for agents

Read the [Authoring, signals, and lifecycle companion](/agents/topics/lifecycle/) for ownership, adaptation, failure modes, and verification. [Agent start](/agents/) provides the version-selection workflow.

## Complete minimal examples

- [Component-owned state and reactions](/minimal-examples/lifecycle/hooks/): Click to update a signal, derive a value, and publish an imperative effect after commit. [Plain source](/minimal/lifecycle/hooks.tsx)
## Documentation version

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