429 (Too Many Requests) Error when using public API in React
The problem:
When calling a public API in useEffect, it will throw a 429 (Too Many Requests) error.
Why does it happen?
There are a few reasons.
- It depends on the API
- It is caused by Strict mode being turned on
Some API limits the user's call interval to regulate the traffic. Also, if strict mode is turned on, useEffect will be called twice. Therefore, the solution would be:
- Turn off strict mode.
- Extend the API request interval.
- Rerun the API call by refreshing the page or implement a API request retry function.
Comments
Post a Comment