Replies: 2 comments
-
In your first example, your atom has a getter function which returns the latest value (and also has automatic dependency tracking). If Jotai would allow updating the value of In the second example, the provided value |
Beta Was this translation helpful? Give feedback.
-
I've discovered that the function const oneAtom = atom(10);
const twoAtom = atomWithDefault(get => get(oneAtom) * 2);
const App = () => {
const [two, setTwo] = useAtom(twoAtom);
return (
<div>
<h1>two: {two}</h1>
<button onClick={() => setTwo(c => c + 1)}>setTwo</button>
</div>
);
}; |
Beta Was this translation helpful? Give feedback.
-
When the
write
function of an atom sets itself, it throws an error,Uncaught Error: atom not writable
.However, when the
read
function is aPrimitiveAtom
, it does not throw an error.Beta Was this translation helpful? Give feedback.
All reactions