The core atomic model of Zedux. This is a standalone package, meaning it's the only package you need to install to use Zedux's atomic model. It includes the Zedux core store package as well as all APIs related to atoms and ecosystems.
This package is framework-independent, though many of its APIs are heavily inspired by React.
If you're new to Zedux, you're probably looking for the quick start.
npm install @zedux/atoms # npm
yarn add @zedux/atoms # yarn
pnpm add @zedux/atoms # pnpm
If you're using React, you probably want to install the @zedux/react
package instead, which includes everything from this package and more.
This package has a direct dependency on the @zedux/core
package. If you install that directly, ensure its version exactly matches your @zedux/atoms
version to prevent installing duplicate packages.
See the top-level README for a general overview of Zedux.
See the Zedux documentation for comprehensive usage details.
Basic example:
import { atom, createEcosystem } from '@zedux/atoms'
const greetingAtom = atom('greeting', 'Hello, World!')
const ecosystem = createEcosystem({ id: 'root' })
const instance = ecosystem.getInstance(greetingAtom)
instance.store.subscribe(newState => console.log('state updated:', newState))
instance.setState('Goodbye, World!')
instance.destroy()
This package includes and re-exports everything from the following package:
On top of this, @zedux/atoms
exports the following APIs and many helper types for working with them in TypeScript:
AtomApi
AtomInstance
AtomInstanceBase
AtomTemplate
AtomTemplateBase
Ecosystem
IonTemplate
SelectorCache
ZeduxPlugin
injectAtomGetters()
injectAtomInstance()
injectAtomSelector()
injectAtomState()
injectAtomValue()
injectCallback()
injectEffect()
injectInvalidate()
injectMemo()
injectPromise()
injectRef()
injectSelf()
injectStore()
injectWhy()
If your lib only uses APIs in this package, it's recommended to only import this package, not @zedux/react
. It's recommended to use a peer dependency + dev dependency on this package.
See the top-level README for all the technical stuff.