Skip to content

Commit

Permalink
set state in render instead of an effect
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Nov 13, 2023
1 parent 2acc01b commit 3639f21
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1547,16 +1547,12 @@ export function useFetcher<TData = any>({

// Fetcher key handling
let [fetcherKey, setFetcherKey] = React.useState<string>(key || "");
if (!fetcherKey) {
if (key && key !== fetcherKey) {
setFetcherKey(key);
} else if (!fetcherKey) {
setFetcherKey(getUniqueFetcherId());
}

React.useEffect(() => {
if (key && key !== "" && key != fetcherKey) {
setFetcherKey(key);
}
}, [key, fetcherKey]);

// Registration/cleanup
React.useEffect(() => {
router.getFetcher(fetcherKey);
Expand Down

0 comments on commit 3639f21

Please sign in to comment.