DEV Community

Cover image for How to persist the data in atoms with local storage using recoil persist.
Next Dev
Next Dev

Posted on

4 1

How to persist the data in atoms with local storage using recoil persist.

Welcome friends 👋. In this blog post, you will learn how to persist the data in local storage in recoil.

For people, who understand Hindi

👁️Situation

Suppose, you are making a to-do list website where people can type todos and todos will be stored in the local storage. But the question arises, how can you persist the data with local storage.

😍Solution

Let’s take an example 👇


In the 👆 example, there is an atom(‘todosAtom’) that is responsible for storing all the todos.

Now, we can use effects_UNSTABLE


Here, we are using **effects_unstable **which runs when the atom is initialized or changed.

But, unfortunately, you will encounter an error if you are using an SSR framework like nextjs.

🤔Then how to solve it?

yarn add recoil-persist
Enter fullscreen mode Exit fullscreen mode

recoil-persist



Now, all of your work would be done with the help of the recoil persist.

If you have any questions, feel free to ask here👇:
Join the Next Dev Discord Server!

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay