# usePersistSession

<!-- https://uncage.vercel.app/docs/api/react/functions/usepersistsession/ -->

```ts
function usePersistSession(mode?): void;
```

Defined in: react/src/hooks.ts:384

Remembers the open session so a reload lands on the same conversation: on mount it reopens the
remembered session (`?session=<id>` with `'url'`, a `localStorage` entry with `'localStorage'`, or
`mode.get()` with a [PersistSessionStorage](https://uncage.vercel.app/docs/api/react/type-aliases/persistsessionstorage.md) adapter), then mirrors the open session there
(`history.replaceState`, no new history entries) and clears it when a new draft is opened. A
remembered session that cannot be opened falls back to a new draft (the error is shown unless the
session simply no longer exists). `<AgentChat>` calls this (default `'url'`); headless UIs call it
once near the root.

An adapter does not need to be referentially stable (an inline `{ get, set }` is fine): it is read
once per mount, and the latest `get` / `set` are used. Switching between modes (e.g. `'url'` to an
adapter) restores again.

## Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `mode?` | [`PersistSessionMode`](https://uncage.vercel.app/docs/api/react/type-aliases/persistsessionmode.md) | `'url'` |

## Returns

`void`
