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 wil…


This content originally appeared on DEV Community and was authored by Next Dev

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

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!


This content originally appeared on DEV Community and was authored by Next Dev


Print Share Comment Cite Upload Translate Updates
APA

Next Dev | Sciencx (2022-07-03T05:03:40+00:00) How to persist the data in atoms with local storage using recoil persist.. Retrieved from https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/

MLA
" » How to persist the data in atoms with local storage using recoil persist.." Next Dev | Sciencx - Sunday July 3, 2022, https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/
HARVARD
Next Dev | Sciencx Sunday July 3, 2022 » How to persist the data in atoms with local storage using recoil persist.., viewed ,<https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/>
VANCOUVER
Next Dev | Sciencx - » How to persist the data in atoms with local storage using recoil persist.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/
CHICAGO
" » How to persist the data in atoms with local storage using recoil persist.." Next Dev | Sciencx - Accessed . https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/
IEEE
" » How to persist the data in atoms with local storage using recoil persist.." Next Dev | Sciencx [Online]. Available: https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/. [Accessed: ]
rf:citation
» How to persist the data in atoms with local storage using recoil persist. | Next Dev | Sciencx | https://www.scien.cx/2022/07/03/how-to-persist-the-data-in-atoms-with-local-storage-using-recoil-persist/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.