React Hooks Patterns/Expose derived async status

Return a status object from custom data hooks.

Section: Data Fetching Patterns

Expose derived async status

tsx
tsx
return {
  data,
  error,
  loading,
  isEmpty: !loading && !error && Array.isArray(data) && data.length === 0,
};
Explanation

Derived flags simplify call sites and reduce repeated UI conditionals.

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
Track loading, error, and data state
Model async UI state explicitly.
OpenIn sheettsxsame section
Basic custom hook
Extract reusable stateful logic into a function.
OpenIn sheettsx3 tag match
Track previous value
Store the previous render’s value.
OpenIn sheettsx3 tag match
Custom hook with options object
Prefer options objects for extensible APIs.
OpenIn sheettsx3 tag match
Persist state to localStorage
Sync component state with localStorage.
OpenIn sheettsx3 tag match