Preserve State by Combining Multiple Jotai Atoms into One Atom

InstructorDaishi Kato

Share this video with your friends

Send Tweet

In the previous lessons, we’ve been able to create and render shapes by storing the data needed into a Jotai atom. You’ll notice that each time you draw a path that the previous path is cleared. This is because we are setting the new path in the old path’s place, it's gone forever.

We can preserve state by aggregating atoms into another single atom by pushing them into an array. Once we have this array, we can map over the array in a new component to draw as many paths as you would like