create
import { create } from 'xoid'
create
is used to create atoms. Atoms are standalone setter/getter objects that hold state.
Atoms can have actions, and with use
function they can be used.
Derived state
By providing a function as the first argument, a derived atom can be created.
Deriving state from other sources (Advanced)
With an additional feature of get
function above, you can get the state from non-atoms. This can be a Redux store, an RxJS observable, or anything that implements getState & subscribe pair. Here is an atom that derives its state from a Redux store.
Grabbing refs
With no arguments used, create
function can be used to grab refs.
Enhanced atoms (Advanced)
An enhanced atom is an atom with different "setter" behavior. Optional third argument of create
is called an enhancer. It's used for returning a function to be used instead of the default setter function. Most people using xoid will not need to write enhancers.
Following is a simple "logger middleware" created with xoid: