npm i einfach-state
import { atom } from 'einfach-state'
const helloWorldAtom = atom('Hello World')
const objAtom = atom({})
import { useAtom, atom } from 'einfach-state';
const countAtom = atom(0)
function Counter() {
const [count, setCount] = useAtom(countAtom);
return (
<h1>
{count}
<button onClick={() => setCount((c) => c + 1)}>one up</button>
</h1>
);
}
import { atom } from 'einfach-state';
const countAtom = atom(0)
const doubleCountAtom = atom((get)=>{
return get(countAtom) * 2
})
import { createStore } from 'einfach-state'
const store = createStore()
const countAtom = atom(0)
function Counter() {
const [count, setCount] = useAtom(countAtom , { store });
return (
<h1>
{count}
<button onClick={() => setCount((c) => c + 1)}>one up</button>
</h1>
);
}