You can skip this part if you've already read the Github README.
xoid has only 4 exports:
use. This section will cover all of them, and the @xoid/react.
Atoms are standalone setter/getter objects that hold state.
create function is used to create them.
Atoms can have actions, and with
use function they can be used.
use function can act as a selector when it's used with a second argument. xoid is based on immutable updates, so if you "surgically" set state of a selected branch, changes will propagate to the root.
Atoms can be derived from other atoms. This API was heavily inspired by Recoil.
effect are used. They are the same, except
effect runs the callback immediately, while
subscribe waits for the first update after subscription.
To cleanup side-effects, a function can be returned in the subscriber function. (Just like
@xoid/react is based on two hooks.
useAtom subscribes the component to an atom. If a second argument is supplied, it'll be used as a selector function.
The other hook is
useSetup. It can be used for creating local component state. It'll run its closure only once. If a second argument is supplied, it'll be used for communication between the closure (
useSetup scope) and outside (React component scope).
useSetupis guaranteed to be non-render-causing. Atoms returned by that should be explicitly subscribed via
This is all you need to know to start using xoid. In the following sections, you'll find more detailed explanation of the API.