useAtom
is a React Hook and must follow the Rules of HooksReads the current state of an Atom and subscribes the currently rendering function component to the Atom's state such that, when the Atom's state changes, the component will automatically re-render to read the new state. The subscription is removed when the component unmounts.
the type of the internal state of the Atom
the internal state of the Atom
useAtom
is a React Hook and must follow the Rules of HooksuseAtom enhanced with options
.
Reads the current state of an Atom and subscribes the currently rendering function component to the Atom's state such that, when the Atom's state changes, the component will automatically re-render to read the new state. The subscription is removed when the component unmounts.
the type of the internal state of the Atom
the type of the return value of useAtom computed via options.select
the value returned from applying options.select
to S
NOTE: This is a back door for users of
react
prior to hooksInitializes
react-atom
with the provided HookDependencies and returns the full public API ofreact-atom
.By default, react-atom imports the HookDependencies from the version of
react
you've installed, butinitialize
provides you the option to use a different implementation of hooks. For example, if you're using a version ofreact
prior to the release of hooks, you might like to use a poly/ponyfill like react-with-hooks.If you use
initialize
, you need to be careful to avoid importinguseAtom
and co. fromreact-atom
and make sure to only use the instances returned byinitialize
throughout your application.import {useLayoutEffect, useMemo, useState} from 'alt-hooks' import { initialize } from '@dbeining/react-atom'; export const {Atom, deref, set, swap, useAtom} = initialize({ useLayoutEffect, useMemo, useState, });