Reference

Compared with Jotai and Recoil

All three split state into atoms and derive the rest. They differ in where the state lives, how atoms are named, and when state is let go.

At a glance

atemnoJotaiRecoil
ScopeFramework agnostic core, with a React bindingReact, with a store usable on its ownReact
Where state livesAn explicit ReactiveDomain, alwaysA default store, Provider optionalA RecoilRoot, required
Atom identityA string name you chooseThe atom objectA string key, unique across the app
Derived statecomputed and writable proxy, lazy, cachedDerived atomsSelectors
Keyed stateatomFactory, computedFactoryatomFamily from jotai-familyatomFamily, selectorFamily
Grouped writesaction, bound to a domainWrite functions on atomsuseRecoilCallback and transactions
Async and Suspenseresource, with Suspense in ReactPromises with SuspenseAsync selectors with Suspense
State lifetimeReleased once nothing tracks itAs long as the storeAs long as the root
MaturityNot released yetStable, widely usedNo longer under active development

A counter

The same counter in each, with a derived value. Pick a tab and every example on this page switches to it.

import { atom, computed } from 'atemno';
import { AtemnoDomain, useAtomState, useComputedValue } from 'atemno/react';

const count = atom('count', 0);
const double = computed<number>('double', $ => $.get(count) * 2);

function Counter() {
  const [value, setCount] = useAtomState(count);
  const doubled = useComputedValue(double);
  return (
    <button onClick={() => setCount(n => n + 1)}>
      {value} × 2 = {doubled}
    </button>
  );
}

export function App() {
  return (
    <AtemnoDomain>
      <Counter />
    </AtemnoDomain>
  );
}

The components are nearly identical. The differences are in the first lines and the last ones: how a piece of state is named, and where it is stored.

Where the state lives

Jotai keeps a default store, so an atom works with no setup and a Provider is something you add for isolation. Recoil puts the store in a RecoilRoot you must render. atemno has no implicit store, so every read names a domain. That is more ceremony in a small app and less on a server, where every request wants its own state and sharing one by accident is a bug.

Here is state for one server request, seeded with the signed-in user:

import { AtemnoDomain } from 'atemno/react';

function renderPage(user: User) {
  return (
    <AtemnoDomain initialize={domain => domain.set(currentUser, user)}>
      <Page />
    </AtemnoDomain>
  );
}

In Jotai, forgetting the Provider falls back to the default store, which one server process shares across every request. atemno has nothing to fall back to: the hooks throw without a domain above them.

Names

Jotai identifies an atom by the object, so there is nothing to keep unique and nothing to collide. atemno and Recoil take a string. That costs a decision per atom and buys a readable handle in devtools, logs and anything else that reads the graph.

The difference shows most in state keyed by an id, one atom per todo:

import { atomFactory } from 'atemno';

const todo = atomFactory('todo', {
  key: (id: number) => `${id}`,
  value: id => ({ id, done: false }),
});

todo(1).name; // "todo/1"

atemno's factory and Recoil's family both derive a name per key, todo/1 in atemno. Jotai's family caches atom objects by key and keeps them until you remove them. atemno's cache holds only descriptions: the state for todo/1 is found by its name, so it survives a description being evicted. See keyed state.

Writing several atoms at once

import { action } from 'atemno';
import { useAction } from 'atemno/react';

const transfer = action(($, amount: number) => {
  $.set(checking, $.get(checking) - amount);
  $.set(savings, $.get(savings) + amount);
});

// In a component
const send = useAction(transfer);
send(50);

An atemno action is a plain function of a context and an argument, so it can be called outside React with domain.getAction(transfer) too. A Jotai write atom lives in the store like any other atom. Recoil's callback is created inside a component.

Lifetime

This is the one real behavioural difference, and the sharpest edge. atemno releases a node once nothing tracks it, so unmounting the last component reading an atom discards its state. Jotai and Recoil keep state for as long as the store or root lives. In atemno, hold a subscription to keep a source alive. See node lifetime.

import { ReactiveDomain, atom } from 'atemno';

const count = atom('count', 0);
const domain = new ReactiveDomain({});

const stop = domain.observe(count, () => {});
domain.set(count, 5);
// Kept: the observer tracks it.
stop();
domain.get(count); // 0, released with its last tracker

Beyond React

The atemno core has no React in it. Every demo on this site uses no framework at all, just one subscription writing to the DOM. Jotai's store also works on its own, through get, set and sub, as the lifetime example shows. Recoil has no supported way to read or write state outside a RecoilRoot.

When to pick the others

Pick Jotai. It is stable, it has a large community, and its async support has been used in production for years. atemno's resources are new, and atemno has not had a release.

Recoil is worth reading for its ideas, but it is no longer under active development, so it is not where new work should start.