A React hook for async data. Loading, error, success: always one state, always type-safe.
const store = useRemoteData(() => fetchUser(id));
<Await store={store}>{(user) => <span>{user.name}</span>}</Await>;Inside the callback, user is User, not User | undefined. You cannot read the value without proving it exists.
Refresh, retry, mutations, lazy loading, typed errors, composing requests; all in one tiny library with zero dependencies beyond React.
Based on the Remote Data pattern: https://medium.com/@gcanti/slaying-a-ui-antipattern-with-flow-5eed0cfb627b
Related: remote-data-ts, remote-data, react-remote-data-hooks