Problem Statement
How to handle loading and error states during API calls?
Explanation
Use three pieces of state: data, loading, and error. Set loading true before fetch, update data on success, and show fallback UI on error.
Code Solution
SolutionRead Only
if(loading)return <p>Loading...</p>;
if(error)return <p>Error!</p>;
return <DataList data={data}/>;Practice Sets
This question appears in the following practice sets: