Skip to content

oyvindberg/use-remote-data

Repository files navigation

use-remote-data

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.

Read the docs

Prior art

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

About

Promise handling for react. Principled, Boilerplate-free, Caching, Invalidating

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors