1. Making API Call while using React Hooks
In Function Component, we can use
API Call using the
1.1 Effects should be Synchronous
It's not a good practice to make an effect asynchronous because it may lead to unexpected results
If you need an asynchronous function, define and call the async function inside the Effect
2. Displaying different views
While making an API call, we need to display different views like Loading View, Success View, and Failure View
For displaying these views, we need to maintain the following values in the state
- Status
- Data
- Error Message
We use a single state variable with an object as an initial value to store these values as they tend to change together
File: src/components/Leaderboard/index.js
Based on the API Status, we display different views
File: src/components/Leaderboard/index.js
3. Leaderboard Application Code
Use the below command to get the Final Code for the Leaderboard Application