React hooks: useSessionStorage and useLocalStorage

So I needed a simple way to use the sessionStorage and localStorage with React, and one of the requirements was to use TypeScript. The idea is pretty simple. It encapsulates the browser sessionStorage or localStorage with the useState hook. The hooks a…


This content originally appeared on DEV Community and was authored by Saulo Dias

So I needed a simple way to use the sessionStorage and localStorage with React, and one of the requirements was to use TypeScript. The idea is pretty simple. It encapsulates the browser sessionStorage or localStorage with the useState hook. The hooks actually return a stateful value, and a function to update it.

You can also customize the STORAGE_KEYS_PREFIX, which can be useful to avoid conflicts between storage keys from different applications you might be developing.


This content originally appeared on DEV Community and was authored by Saulo Dias


Print Share Comment Cite Upload Translate Updates
APA

Saulo Dias | Sciencx (2022-07-01T04:46:40+00:00) React hooks: useSessionStorage and useLocalStorage. Retrieved from https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/

MLA
" » React hooks: useSessionStorage and useLocalStorage." Saulo Dias | Sciencx - Friday July 1, 2022, https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/
HARVARD
Saulo Dias | Sciencx Friday July 1, 2022 » React hooks: useSessionStorage and useLocalStorage., viewed ,<https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/>
VANCOUVER
Saulo Dias | Sciencx - » React hooks: useSessionStorage and useLocalStorage. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/
CHICAGO
" » React hooks: useSessionStorage and useLocalStorage." Saulo Dias | Sciencx - Accessed . https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/
IEEE
" » React hooks: useSessionStorage and useLocalStorage." Saulo Dias | Sciencx [Online]. Available: https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/. [Accessed: ]
rf:citation
» React hooks: useSessionStorage and useLocalStorage | Saulo Dias | Sciencx | https://www.scien.cx/2022/07/01/react-hooks-usesessionstorage-and-uselocalstorage/ |

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.