Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/jotai-loadable. A tiny helper that turns async Jotai atoms into loadable atoms
Something went wrong. Try again.
TypeScript 91%
JavaScript 7%
2%
Commits 28
Bump postcss from 8.5.22 to 8.5.26
Signed-off-by: dependabot[bot] <support@github.com>
README.md
Jotai-Loadable #
Turn an async Jotai atom into a loadable atom with loading, hasData, and hasError states.
tl;dr #
- Install by executing
npm install jotai jotai-loadableoryarn add jotai jotai-loadable. - Import by adding
import { loadable } from 'jotai-loadable'. - Use it by writing
const loadableAtom = loadable(asyncAtom).
Examples #
import { atom } from 'jotai';
import { loadable } from 'jotai-loadable';
const asyncAtom = atom(async () => {
const response = await fetch('/api/user');
return response.json() as Promise<{ name: string }>;
});
const loadableAtom = loadable(asyncAtom);
// {
// state: 'loading'
// }
//
// {
// state: 'hasData',
// data: { name: 'Wojciech' }
// }
//
// {
// state: 'hasError',
// error: Error
// }
License #
The MIT License.
Author #
|
|
Wojciech Maj |