1. 2
    Derive Jotai Atom State from Complex State Managed in Xstate
    3m 21s

Derive Jotai Atom State from Complex State Managed in Xstate

InstructorDaishi Kato

Share this video with your friends

Send Tweet

Sometimes you need to display values in specific ways throughout your application based on the state that you are managing. The way to do this is to derive your state so you don't have to track multiple stateful items.

In Jotai, this is accomplished by creating an atom, getting the value from another atom that you are managing (in this case from Xstate), and using that value how you need it in your derived atom. This atom will be re-evaluated every time the managed state changes.

This pattern is great to use if you have complex state managed in something like Xstate but need a derived state value that is not strongly tied to that managed state. The pattern works the same for async and synchronous function calls as well as pulling in multiple atoms and libraries to use in your derived state.