Created
November 5, 2022 16:49
-
-
Save ryanflorence/8af9f48ecae743888e1e29991c54ab97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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