question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useFetch: Infinite re-rendering only when NODE_ENV=production

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
supermihicommented, Sep 2, 2019

Perfect, thanks for the quick fix!

1reaction
supermihicommented, Aug 5, 2019

Sure, I’ll try to build a reproducible example asap.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found