Component - Loading and error states
This component shows how a mobile app screen handles loading data and errors. It displays a loading spinner while waiting, shows the data when ready, or an error message if something goes wrong.
This component shows how a mobile app screen handles loading data and errors. It displays a loading spinner while waiting, shows the data when ready, or an error message if something goes wrong.
View ├─ ActivityIndicator ├─ Text (Data or Error message) └─ Button (Retry)
loading is true?const [loading, setLoading] = useState(true); return ( loading ? Loading... : Data loaded );
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
if (loading) {
return Loading...;
} else if (error) {
return Error occurred;
}
return Data loaded;Pass the test and this pattern moves unknown