From f36d28a0a8d72f51604e5df3dbde469898ecf65b Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Tue, 13 Feb 2024 16:07:15 +0100 Subject: [PATCH] Improve the documentation around useFetcher to explain that fetcher.submit is stable across rerenders This was implemented originally in https://github.com/remix-run/react-router/pull/10336. --- docs/hooks/use-fetcher.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/hooks/use-fetcher.md b/docs/hooks/use-fetcher.md index a11b14d2bf..2788fce47b 100644 --- a/docs/hooks/use-fetcher.md +++ b/docs/hooks/use-fetcher.md @@ -32,8 +32,11 @@ function SomeComponent() { // call submit or load in a useEffect React.useEffect(() => { fetcher.submit(data, options); + }, [fetcher.submit]); // fetcher.submit is stable, fetcher isn't. + + React.useEffect(() => { fetcher.load(href); - }, [fetcher]); + }, [fetcher.load]); // build your UI with these properties fetcher.state; @@ -160,7 +163,7 @@ export function useIdleLogout() { { method: "post", action: "/logout" } ); } - }, [userIsIdle]); + }, [userIsIdle, fetcher.submit]); } ```