Reputation: 1269
I want to add a color theme for a specific page that will color me when the button is clicked, the color theme will have 3 or 4 primary colors, my question is, is it worth using localstorage for this task? I want the selected theme not to disappear when the page is refreshed
Upvotes: 0
Views: 802
Reputation: 36
If you're using Redux, you can use redux-persist npm i redux-persist
which uses localstorage as Hoargarth suggested. The difference being you don't have to manage the setting and getting of the key-value in the browser, instead, define your color props in your reducer and dispatch an action to update it with your button handler and redux-persist will manage persisting your state after refresh and closing the browser.
Upvotes: 2
Reputation: 1616
I would say yes, since the other two options are only sessionstorage
or cookies
.
Sessionstorage: This one would be an option too if it's ok for you if the value disappears when the user is closing his browser (or tab, depending on settings)
Cookies: You could also use cookies, but the drawback would be, that cookies are always sent to the server. And as long as you don't do anything with the cookie on server side, this is a waste of computing time.
So in my opinion, localstorage
should be the way to go.
Upvotes: 3