Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 495 Bytes

README.md

File metadata and controls

21 lines (16 loc) · 495 Bytes

Jotai

A jotai clone for vanilla JS, made for fun and for my own use.

import { createStore, atom } from "@madahapa/jotai";

const store = createStore();
const countAtom = atom(0);
const doubleCountAtom = atom(
  (get) => get(countAtom) * 2,
  (get, set, value: number) => set(countAtom, value / 2)
);

const unsubscribe = store.subscribe(doubleCountAtom, function () {
  console.log(store.get(doubleCountAtom));
});

store.set(countAtom, (prev) => prev + 1);
unsubscribe();