How to use local storage in React




In this post, we will see how to use Localstorage in react.

To write data into local storage

If you want to write some data into local storage, you can do like below

localStorage.setItem("key" , "value");

To read data from local storage

If you want to read some data from local storage, you can do like below

localStorage.getItem("key");

Removing data from local storage

If you want to remove some data from local storage, you can do like below

localStorage.removeItem("key");

Clear local storage

If you want to clear all data in local storage you can do like below,

localStorage.clear();