GoogleChromeLabs / GoogleChromeLabs/react-adaptive-hooks

Too many re-renders. React limits the number of renders to prevent an infinite loop

Open
#77 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.2k
Forks
112
PR merge metrics
No merged PRs in 30d

Description

I Implemented `effectiveConnectionType` to detect the network signal strength. When I call the function may be its going in infinite loop and returning following error in console:

![image](https://user-images.githubusercontent.com/110804074/190078689-f6232114-13f6-4f3a-a085-2d24a0e6baa6.png)

Its going multiple times in switch cases. This is my function:
```

const MeasureConnectionSpeed = () => {
const { effectiveConnectionType } = useNetworkStatus();
switch(effectiveConnectionType) {
case 'slow-2g':
setNetworkStrength("WEAK");
break;
case '2g':
setNetworkStrength("OKAY");
break;
case '3g':
setNetworkStrength("GREAT");
break;
case '4g':
setNetworkStrength("EXCELLENT");
break;
default:
break;
}
}
MeasureConnectionSpeed();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.