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.
refresh(): void;refresh does not return a value.
filename="app/actions.ts" switcher
'use server'
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()
}filename="app/actions.js" switcher
'use server'
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()
}filename="app/api/posts/route.ts" switcher
export async function POST() {
// This will throw an error
refresh()
}