K
K
Kentavr162021-06-11 19:59:02
React
Kentavr16, 2021-06-11 19:59:02

Is it possible to use the browser's local storage to store the state of a react application?

I came up with the idea to use local storage to store the state of the application. In theory, it can be convenient - without registration / login, the user will save the selected topic, for example. Is this approach reasonable?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2021-06-11
@Kentavr16

There are no cons and many people do it.
For this, in general, localstorage / sessionstorage were invented.
You can’t just put any sensitive data in local storage, such as passwords, tokens, and sessions.

I
Ilya, 2021-06-11
@sarapinit

Yes, in general, like any cache, problems begin when it needs to be disabled. You can overwrite cookies from the server.
Well, there may still be problems if the code writes something crookedly and breaks your structure (if it exists, of course). That is, if you save an object, then you need to be prepared that it may return invalid from the storage. But these are rather problems for large applications with several developers.

N
Nadim Zakirov, 2021-06-12
@zkrvndm

For these purposes it is better to use IndexedDB.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question