Jotai Derived Atoms: Computed State from Other Atoms

Think of a derived atom like a spreadsheet formula: its value is computed from other atoms. Use it for reactive values like a cart total from item prices. The footgun: the get in your read function is reactive, but the get in your write function.
Why it exists
To avoid manual state synchronization. In complex apps, many pieces of state are based on other state, like a form's validity depending on its inputs. Derived atoms let you declare these relationships, letting Jotai manage updates instead of you writing imperative useEffect logic.
The mental model
A derived atom is a computed property for your global state. It doesn't hold its own independent value; instead, it runs a function to calculate its value whenever one of its dependencies changes. Think of a totalPriceAtom that automatically recalculates when item1PriceAtom or item2PriceAtom is updated.
How it works
You create a derived atom by passing a read function to atom(). This function receives a get argument. You use get(someOtherAtom) to read a dependency's value, and Jotai tracks this dependency. When a dependency changes, Jotai re-runs your read function. You can also provide an optional second write function to allow setting the derived atom, which in turn updates the underlying source atoms. For example, setting a fullNameAtom could update firstNameAtom and lastNameAtom.
When to use it
Use derived atoms for any state that is a pure function of other state. Common cases include: calculating a shopping cart total from item atoms, filtering a list based on a search query atom, determining if a form is valid based on its input field atoms, or combining a first name and last name into a full name.
When not to use it
Do not use derived atoms for values that are truly independent pieces of state. If a value needs to be set directly and doesn't depend on anything else, use a primitive atom: atom(initialValue). Also, avoid creating complex, deeply nested chains of derived atoms, as they can make debugging difficult to trace.
One canonical example
A read-write derived atom for temperature conversion. A celsiusAtom holds the source value. A fahrenheitAtom is derived from it, but can also be written to, which then updates the original celsiusAtom.
const celsiusAtom = atom(0);
const fahrenheitAtom = atom(
(get) => get(celsiusAtom) * 9/5 + 32,
(get, set, newFahrenheit) => {
set(celsiusAtom, (newFahrenheit - 32) * 5/9);
}
);Updating fahrenheitAtom to 212 will automatically update celsiusAtom to 100, and vice versa.
Interview question
Which statement accurately describes the behavior of the 'get' function within a Jotai derived atom's definition?
- a.The 'get' function is only available in the read part; the write part uses 'set' exclusively.
- b.The 'get' function in the read part tracks dependencies, but the 'get' function in the write part does not.Correct
- c.The 'get' function in the write part is used to set the derived atom's initial value.
- d.Both the 'get' function in the read part and the 'get' function in the write part track dependencies.
Why? this is the answer
The card explicitly states that 'the get in your read function is reactive, but the get in your write function.' This means the 'get' in the read function tracks dependencies, while the 'get' in the write function does not. Option D is a common misconception, assuming 'get' always behaves reactively.
Just read this? Test yourself on what you have been reading.
Read the original → jotai.org
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.
See open roles