Add Additional Functionality by Creating Jotai Atoms that Hold Atoms

InstructorDaishi Kato

Share this video with your friends

Send Tweet

Atoms can take just about anything as input, this includes other Atoms as well! You will see how we can take an atom, ShapeAtom, as input so that we can highlight the shape that we select.

To do this, we will need to export two functions for you to consume elsewhere. One that sets the the input (an atom) as the atom contained within our newly created atom. The other function will determine if a current shape is selected or not. This will be done by deriving the selected atom from our newly created atom and returning a boolean if it matches the original shape.

With these two functions we can apply additional styles to shapes that are selected.