useFetch: Infinite re-rendering only when NODE_ENV=production
See original GitHub issueI am experiencing an infinite re-rendering (leading to infinite re-fetch) with the useFetch
hook, but only when building in production mode (NODE_ENV=production
), not in development-build or running with webpack dev-server.
Honestly I have no clues on how to further debug the issue. The hook depends on a static string only:
export default ({ selection, setSelection }: Props) => {
const { result: availableData, ...props } = useFetch<AvailableDataMap>(dataFilesUrl);
const nodes = useSelector(selectNodes);
if (props.error) return <Alert color="error">{`Error fetching data: ${props.error}`}</Alert>;
if (props.pending) return <Spinner type="grow" />;
if (!selection || selection.length === 0) {
setSelection(Object.keys(availableData).map(nodeId => ({ nodeId, filename: availableData[nodeId][0] })));
}
/* ... */
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
My useFetch hook is giving me too many re-renders
This may cause the state to be updated on every render, which forces re-render and creates an infinite render loop. Instead, state should...
Read more >Preventing infinite re-renders when using useEffect and ...
Changing state will always cause a re-render. By default, useEffect always runs after render has run. This means if you don't include a...
Read more >useQuery infinite loop re-rendering #3644 - GitHub
The initial render went fine. It's only after the poll is being triggered, that the query gets stuck in a loop. The component...
Read more >3 ways to cause an infinite loop in React - Alex Sidorenko
Fix. Do you want to update a state only one time when the component mounts? Use useEffect with an empty array as a...
Read more >React Hooks - Understanding Component Re-renders - Medium
If you are interested in only a specific hook, please go directly from the ... Most of the times infinite re-renders are a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Perfect, thanks for the quick fix!
Sure, I’ll try to build a reproducible example asap.