Arguments passed to shouldRevalidate function

interface ShouldRevalidateFunctionArgs {
    actionResult?: any;
    actionStatus?: number;
    currentParams: Params<string>;
    currentUrl: URL;
    defaultShouldRevalidate: boolean;
    formAction?: string;
    formData?: FormData;
    formEncType?: FormEncType;
    formMethod?:
        | "GET"
        | "POST"
        | "PUT"
        | "PATCH"
        | "DELETE";
    json?: JsonValue;
    nextParams: Params<string>;
    nextUrl: URL;
    text?: string;
}

Properties

actionResult?: any

When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.

export async function action() {
await saveSomeStuff();
return { ok: true };
}

export function shouldRevalidate({
actionResult,
}) {
if (actionResult?.ok) {
return false;
}
return true;
}
actionStatus?: number

The status code of the action response

currentParams: Params<string>

These are the dynamic route params from the URL that can be compared to the nextParams to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed.

currentUrl: URL

This is the url the navigation started from. You can compare it with nextUrl to decide if you need to revalidate this route's data.

defaultShouldRevalidate: boolean

By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:

/projects/123/tasks/abc /projects/123/tasks/def React Router will only call the loader for tasks/def because the param for projects/123 didn't change.

It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.

formAction?: string

The form action (<Form action="/somewhere">) that triggered the revalidation.

formData?: FormData

The form submission data when the form's encType is application/x-www-form-urlencoded or multipart/form-data

formEncType?: FormEncType

The form encType (`

) used in the form submission that triggered the revalidation

formMethod?:
    | "GET"
    | "POST"
    | "PUT"
    | "PATCH"
    | "DELETE"

The method (probably "GET" or "POST") used in the form submission that triggered the revalidation.

json?: JsonValue

The form submission data when the form's encType is application/json

nextParams: Params<string>

In the case of navigation, these are the dynamic route params from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams.

nextUrl: URL

In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl.

text?: string

The form submission data when the form's encType is text/plain