Buckets:
| --- | |
| title: refresh | |
| description: API Reference for the refresh function. | |
| --- | |
| `refresh` allows you to refresh the client router from within a [Server Action](/docs/app/getting-started/mutating-data). | |
| ## Usage | |
| `refresh` can **only** be called from within Server Actions. It cannot be used in Route Handlers, Client Components, or any other context. | |
| ## Parameters | |
| ```tsx | |
| refresh(): void; | |
| ``` | |
| ## Returns | |
| `refresh` does not return a value. | |
| ## Examples | |
| ```ts filename="app/actions.ts" switcher | |
| 'use server' | |
| import { refresh } from 'next/cache' | |
| export async function createPost(formData: FormData) { | |
| const title = formData.get('title') | |
| const content = formData.get('content') | |
| // Create the post in your database | |
| const post = await db.post.create({ | |
| data: { title, content }, | |
| }) | |
| refresh() | |
| } | |
| ``` | |
| ```js filename="app/actions.js" switcher | |
| 'use server' | |
| import { refresh } from 'next/cache' | |
| export async function createPost(formData) { | |
| const title = formData.get('title') | |
| const content = formData.get('content') | |
| // Create the post in your database | |
| const post = await db.post.create({ | |
| data: { title, content }, | |
| }) | |
| refresh() | |
| } | |
| ``` | |
| ### Error when used outside Server Actions | |
| ```ts filename="app/api/posts/route.ts" switcher | |
| import { refresh } from 'next/cache' | |
| export async function POST() { | |
| // This will throw an error | |
| refresh() | |
| } | |
| ``` | |
Xet Storage Details
- Size:
- 1.38 kB
- Xet hash:
- 7735e0b104999bdaee4062adcd5f3e39c585e82e30fe2cb82d0e38c6d61e85ec
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.