Complete the code to import the function used to revalidate a path after mutation in Next.js.
import { [1] } from 'next/cache';
The revalidatePath function from next/cache is used to trigger revalidation of a specific path after a mutation.
Complete the code to call the revalidation function for the '/dashboard' path after a data mutation.
async function updateData() {
// perform mutation
await mutateData();
[1]('/dashboard');
}After mutating data, calling revalidatePath('/dashboard') tells Next.js to refresh the cached data for that path.
Fix the error in this mutation handler by correctly revalidating the path '/profile' after updating user data.
export async function POST(request) {
await updateUser(request.json());
[1]('/profile');
return new Response(null, { status: 200 });
}Using revalidatePath('/profile') after updating user data triggers Next.js to refresh the cached page for '/profile'.
Fill both blanks to import and use the revalidation function correctly after a mutation in Next.js.
import { [1] } from 'next/cache'; export async function PATCH(request) { await updateSettings(request.json()); [2]('/settings'); return new Response(null, { status: 200 }); }
Importing and calling revalidatePath ensures the '/settings' page cache is refreshed after mutation.
Fill all three blanks to create a mutation handler that updates data, revalidates the path, and returns a success response.
import { [1] } from 'next/cache'; export async function PUT(request) { const data = await request.json(); await [2](data); [3]('/account'); return new Response(null, { status: 200 }); }
This code imports revalidatePath, calls updateAccount to mutate data, then calls revalidatePath('/account') to refresh the cache.