Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@zedux/core

Omnistac14.3kMIT1.3.4TypeScript support: included

A high-level, declarative, composable form of Redux

abstraction, beautiful, boilerplate, easy, flux, functional, immutable, management, memoized, performant, reducer, redux, simple, state, zedux

readme

Zedux

Build Status codecov.io npm license

A Molecular State Engine for React.

Zedux is a multi-paradigm state management tool that features a powerful composable store model wrapped in a DI-driven atomic architecture.

Installation

npm install @zedux/react # npm
yarn add @zedux/react # yarn
pnpm add @zedux/react # pnpm

The React package (@zedux/react) contains everything you need to use Zedux in a React app - the core store model, the core atomic model, and the React-specific APIs.

@zedux/react has a peer dependency on React. It supports React version 18 and up.

Intro

We borrowed ideas from dozens of state management tools over the past 5 years, invented a few ourselves, and put it all together in one powerhouse of a state management library.

Most notably, Zedux borrows ideas from Redux, Recoil, and React Query. Zedux takes the unique approach of separating the state layer (stores) from the architecture layer (atoms). This allows for a powerful Dependency Injection model, conceptually similar to Angular's but simpler and more dynamic.

Sound complex? Zedux is actually very beginner-friendly. In fact, here's all you need to begin:

import { atom, useAtomState } from '@zedux/react'

const greetingAtom = atom('greeting', 'Hello, World!')

function Greeting() {
  const [greeting, setGreeting] = useAtomState(greetingAtom)

  return (
    <input
      onChange={event => setGreeting(event.target.value)}
      value={greeting}
    />
  )
}

We'll break down this example and so much more in the docs.

Learn Zedux

To embark on the journey of mastering Zedux, jump into the quick start.

If you prefer something more high-level, the introduction's a decent place to start. Or if you want to learn Everything Everywhere All at Once, the API docs or repo source code and tests are real page-turners.

Happy coding!

Contributing

Contributions an any level are absolutely welcome! Have a look at the contribution guidelines.

Bugs can be reported here.

Questions, feature requests, ideas, and links to cool projects or examples are always welcome in the discussions page.

License

The MIT License.

changelog

v1.3.4 (Feb 15, 2025)

Fixes:

  • react: only trigger rerender in useAtomInstance if subscribe: true (#183)

v1.3.3 (Feb 7, 2025)

Fixes:

  • react: ensure edges are materialized when React runs effects (#166)

v1.3.2 (Feb 5, 2025)

Fixes:

  • react: guard against circular prevCache refs in useAtomSelector (#161)

v1.3.1 (Jan 22, 2025)

Fixes:

  • immer: import named produce export from immer (#148)
  • atoms, react: use singly-linked WeakRefs to clean up React 18 StrictMode trash (#154)

v1.3.0 (Dec 11, 2024)

Since React 19 is officially released, we can finally release v1.3.0 officially. In addition to the selector changes from this version's release candidates, this version removes Zedux's package.json production exports, which were previously unused except by some rogue build pipelines. Credit to @marbemac :tada:.

Fixes:

  • react: fallback to React 18 internals for getting component names (#139)
  • atoms, core, immer, machines, react: remove package.json production exports (#137)

v1.3.0-rc.2 (Jul 31, 2024)

Fixes:

  • react: only rerun useAtomSelector effect on cache id change (#110)

v1.3.0-rc.1 (Jul 30, 2024)

Fixes:

  • react: restore useAtomSelector mounted state when swapping inline refs (#108)

v1.3.0-rc.0 (Jul 30, 2024)

This version contains huge fixes for useAtomSelector that are only fully compatible with React 19 or with React 18 when not using StrictMode. It's recommended to wait for React 19 before upgrading to this version.

Fixes:

  • atoms, react: optimize useAtomSelector for React 19 (#106)

v1.2.3 (Sep 7, 2024)

Fixes:

  • react: make useAtomSelector wait for idle time to do failsafe cleanup (#113)

v1.2.2 (Jun 13, 2024)

Fixes:

  • atoms: disable ecosystem.find() fuzzy search if params are passed (#103)

v1.2.2-rc.0 (May 30, 2024)

Fixes:

  • atoms, react: useAtomSelector - subscribe to the new selector before destroying the old (#101)

v1.2.1 (May 14, 2024)

Fixes:

  • core: allow store-extending classes to have array state types (#96)
  • core: always notify effects subscribers when a hydration has metadata (#98)

v1.2.0 (Feb 6, 2024)

This is mostly a republish of the last v1.2.0 release candidate. Looks good :+1:

Fixes:

  • react: improve types for AtomProvider (#92)

v1.2.0-rc.1 (Nov 20, 2023)

Fixes:

  • react: handle unstable inline selector results in useAtomSelector (#88)

v1.2.0-rc.0 (Nov 14, 2023)

This release featured a near-full rewrite of the useAtomInstance and useAtomSelector hooks. They should be stable, but we're releasing a release candidate version first to verify

New Features:

  • atoms, react: remove uSES usages and support strict mode (#86)

v1.1.1 (Sep 9, 2023)

New Features:

  • atoms: give atom instances access to their real template type (#81)
  • atoms: make ecosystem.find() do a fuzzy search when no exact match (#79)

v1.1.0 (Aug 1, 2023)

Republish of v1.1.0-rc.0 with no additional changes since the release candidate looks good

New Features:

  • atoms: add runOnInvalidate option to injectPromise (#69)
  • atoms: deprecate injectInvalidate (prefer injectSelf) (#70)
  • core: micro-optimize iterating and removing store subscribers (#76)

Fixes:

  • atoms: make query atoms retain data (#68)
  • core: point core package's field to the correct file (#75)
  • react: fix multiple renderers cross-window React warning (#72)
  • atoms, immer, machines: prevent injectors from consuming hydrations (#71)

v1.1.0-rc.0 (Jul 22, 2023)

New Features:

  • atoms: add runOnInvalidate option to injectPromise (#69)
  • atoms: deprecate injectInvalidate (prefer injectSelf) (#70)
  • core: micro-optimize iterating and removing store subscribers (#76)

Fixes:

  • atoms: make query atoms retain data (#68)
  • core: point core package's field to the correct file (#75)
  • react: fix multiple renderers cross-window React warning (#72)
  • atoms, immer, machines: prevent injectors from consuming hydrations (#71)

v1.0.3 (Jun 23, 2023)

Fixes:

  • atoms: let the WeakMap clean up selector ref keys (#66)
  • atoms: make data retention consistent across injectPromise and api(promise) (#65)

v1.0.2 (May 19, 2023)

Zedux got a big speed boost! In practice it won't matter much, but Zedux should now perform even better on stress tests and benchmarks. Enjoy!

New Features:

  • atoms: allow setting promise to undefined in AtomApi (#58)
  • atoms: improve graph perf by removing unnecessary Object.keys() calls (#52)
  • atoms: improve non-TS .getInstance() usage by throwing helpful errors (#59)
  • atoms, react: make atoms package fully framework agnostic (#51)

Fixes:

  • atoms: improve atom searching (#57)
  • atoms: make it easier for TS to infer AtomApi types from chained methods (#49)
  • react: make React imports specify file extensions in esm builds (#53)
  • react: update React peer dep to a minimum of v16.3.0 (#54)
  • atoms, react: improve overloads of atom-template-accepting functions for paramless atoms (#50)
  • atoms, core, immer, machines, react: fix package.json export order (#56)

v1.0.1 (Apr 28, 2023)

Fixes:

  • atoms: improve id generation; prevent selector with args cache reuse edge case (#46)
  • react: use useSyncExternalStore shim for now (#45)

v1.0.0 (Apr 24, 2023)

Zedux's API is officially stable. We have several additions planned, but no breaking changes for any user-facing or documented APIs in the pipeline for the near future. It's go time!

New Features:

  • Breaking Change atoms: defaultTtl -> atomDefaults.ttl (#38)
  • Breaking Change atoms: implement AtomApiGenerics type map and all its helpers (#40)
  • Breaking Change react: AtomInstanceProvider -> AtomProvider (#32)
  • Breaking Change react: make instance.invalidate() a normal method (#29)
  • Breaking Change react: move auto-batching from api() to injectCallback() (#31)
  • Breaking Change react: reuse names that can be shared between instances & selectors (#30)
  • Breaking Change react: useAtomConsumer -> useAtomContext (#33)
  • Breaking Change atoms, immer: don't export createInjector - replace with injectSelf (#35)
  • Breaking Change atoms, core, machines: break out state machines into their own @zedux/machines package (#36)
  • Breaking Change atoms, core, immer, machines, react: internalTypes -> zeduxTypes (#37)
  • atoms, react: break the atomic model into its own @zedux/atoms package (#34)

v1.0.0-rc.0 (Apr 24, 2023)

New Features:

  • Breaking Change atoms: defaultTtl -> atomDefaults.ttl (#38)
  • Breaking Change atoms: implement AtomApiGenerics type map and all its helpers (#40)
  • Breaking Change react: AtomInstanceProvider -> AtomProvider (#32)
  • Breaking Change react: make instance.invalidate() a normal method (#29)
  • Breaking Change react: move auto-batching from api() to injectCallback() (#31)
  • Breaking Change react: reuse names that can be shared between instances & selectors (#30)
  • Breaking Change react: useAtomConsumer -> useAtomContext (#33)
  • Breaking Change atoms, immer: don't export createInjector - replace with injectSelf (#35)
  • Breaking Change atoms, core, machines: break out state machines into their own @zedux/machines package (#36)
  • Breaking Change atoms, core, immer, machines, react: internalTypes -> zeduxTypes (#37)
  • atoms, react: break the atomic model into its own @zedux/atoms package (#34)

v0.5.11 (Apr 20, 2023)

New Features:

  • react: export SelectorCache class (#14)
  • react: make selectors trigger statusChanged mod events on init and destroy (#15)
  • react: make timestamp generation easily overridable; fix statusChanged event order (#17)
  • react: make useAtomConsumer log instead of throw an error when instance is Destroyed
  • react: simplify inline selector detection (#22)
  • react: wrap scheduler run in try...finally; add handling for destroyed instances (#21)

Fixes:

  • react: make DEV mode React component id generation work in SpiderMonkey (#20)
  • react: prevent controller.abort() from isolating the abort fn (#27)
  • react: remove dehydrated state generic from ssr atom config options for now (#16)
  • react: restore Active status when an atom instance is revived (#13)
  • core, react: improve state.on and Observable types (#12)

v0.5.10 (Apr 13, 2023)

Fixes:

  • react: make all stores of all atoms in the evaluation stack use the ecosystem's scheduler (#10)

v0.5.9 (Apr 13, 2023)

Republish v0.5.8 with build cache issue fixed

v0.5.8 (Apr 13, 2023)

Fixes:

  • react: make useAtomSelector rerender components when the selector value becomes undefined (#8)

v0.5.7 (Apr 12, 2023)

New Features:

  • core: expose detailedTypeof and isPlainObject from core package
  • core: remove addMeta and hasMeta

Fixes:

  • react: fix api() Exports type default
  • react: fix api() Promise type inference when returning result immediately
  • react: make EvaluationStack restore store scheduler context in all cases