React Hooks Patterns/Track loading, error, and data state

Model async UI state explicitly.

Section: Data Fetching Patterns

Track loading, error, and data state

tsx
tsx
const [data, setData] = useState<User[] | null>(null);
const [error, setError] = useState<Error | null>(null);
const [loading, setLoading] = useState(false);
Explanation

A simple foundation for robust async UIs before introducing a data library.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Data Fetching Patterns
Fetch with AbortController
Cancel stale requests on dependency change.
OpenIn sheettsxsame section
Expose derived async status
Return a status object from custom data hooks.
OpenIn sheettsxsame section
Basic custom hook
Extract reusable stateful logic into a function.
OpenIn sheettsx2 tag match
Track previous value
Store the previous render’s value.
OpenIn sheettsx2 tag match
Controlled form state
Manage a form object with useState.
OpenIn sheettsx2 tag match
Custom hook with options object
Prefer options objects for extensible APIs.
OpenIn sheettsx2 tag match