Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created November 5, 2022 16:49
Show Gist options
  • Save ryanflorence/8af9f48ecae743888e1e29991c54ab97 to your computer and use it in GitHub Desktop.
Save ryanflorence/8af9f48ecae743888e1e29991c54ab97 to your computer and use it in GitHub Desktop.
import { useFetcher } from "@remix-run/react";
import { useCallback, useMemo } from "react";
export function useRevalidator() {
let fetcher = useFetcher();
let revalidate = useCallback(
() => {
fetcher.submit(null, { action: "/", method: "post" });
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
return useMemo(() => ({ revalidate }), [revalidate]);
}
/////////////////////
// in root.tsx
export function action() {
return { ok: true };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment