> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Function: useRef()

## Call Signature

> **useRef**\<`T`>(`initialValue`: `T`): `RefObject`\<`T`>

`useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
(`initialValue`). The returned object will persist for the full lifetime of the component.

Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
value around similar to how you’d use instance fields in classes.

### Type Parameters

| Type Parameter |
| -------------- |
| `T`            |

### Parameters

| Parameter      | Type |
| -------------- | ---- |
| `initialValue` | `T`  |

### Returns

`RefObject`\<`T`>

### Version

16.8.0

### See

[https://react.dev/reference/react/useRef](https://react.dev/reference/react/useRef)

## Call Signature

> **useRef**\<`T`>(`initialValue`: `T` | `null`): `RefObject`\<`T` | `null`>

`useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
(`initialValue`). The returned object will persist for the full lifetime of the component.

Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
value around similar to how you’d use instance fields in classes.

### Type Parameters

| Type Parameter |
| -------------- |
| `T`            |

### Parameters

| Parameter      | Type          |
| -------------- | ------------- |
| `initialValue` | `T` \| `null` |

### Returns

`RefObject`\<`T` | `null`>

### Version

16.8.0

### See

[https://react.dev/reference/react/useRef](https://react.dev/reference/react/useRef)

## Call Signature

> **useRef**\<`T`>(`initialValue`: `T` | `undefined`): `RefObject`\<`T` | `undefined`>

`useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
(`initialValue`). The returned object will persist for the full lifetime of the component.

Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
value around similar to how you’d use instance fields in classes.

### Type Parameters

| Type Parameter |
| -------------- |
| `T`            |

### Parameters

| Parameter      | Type               |
| -------------- | ------------------ |
| `initialValue` | `T` \| `undefined` |

### Returns

`RefObject`\<`T` | `undefined`>

### Version

16.8.0

### See

[https://react.dev/reference/react/useRef](https://react.dev/reference/react/useRef)
