refresh
Source URL: https://nextjs.org/docs/app/api-reference/functions/refresh
refresh
Section titled “refresh”refresh allows you to refresh the client router from within a Server Action.
refresh can only be called from within Server Actions. It cannot be used in Route Handlers, Client Components, or any other context.
Parameters
Section titled “Parameters”refresh(): void;Returns
Section titled “Returns”refresh does not return a value.
Examples
Section titled “Examples”'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()}'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
Section titled “Error when used outside Server Actions”import { refresh } from 'next/cache'
export async function POST() { // This will throw an error refresh()}