@m1st1ck/atomjs-react
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

AtomJS React

React hook for atomjs

Install

npm install @m1st1ck/atomjs
npm install @m1st1ck/atomjs-react

useAtom<T>(atom: ObservableAtom, shouldUpdate?: (prev: T, next: T) => boolean): T

import { asyncAtom, atom } from "@m1st1ck/atomjs";
import { useAtom } from "@m1st1ck/atomjs-react";

const nameAtom = asyncAtom("Stad");
const countAtom = atom(0);
// listen for state changes and rerender component
const [name, { loading }] = useAtom(nameAtom);
const count = useAtom(countAtom);

Custom equality

const userAtom = atom({ name: "Stad", age: 3 });
// rerender only if age was changed
const user = useAtom(userAtom, (prev, next) => prev.age !== next.age);

Package Sidebar

Install

npm i @m1st1ck/atomjs-react

Weekly Downloads

10

Version

1.0.0

License

ISC

Unpacked Size

5.71 kB

Total Files

8

Last publish

Collaborators

  • m1st1ck