Viewed 6 times 0 I am creating a settings portion on a website. LocalStorage, sessionStorage - JavaScript LocalStorage, sessionStorage. LocalStorage vs. Cookies: All You Need to Know About Storing JWT Tokens ... HTML JavaScript CSS local-storage. Step 4: This is the most important step as this involves saving the state to the local storage of the browser. useEffect ( () => { window.localStorage.setItem ('MY_APP_STATE', JSON.stringify (showBanner)); }, [showBanner]); Here we're using localStorage's setItem method passing . Window localStorage Property - W3Schools Concrete recommendations are provided at the end. index.html The data is bound to the origin (domain/port/protocol). Local storage has a significantly higher storage limit (5MB vs 4KB) and doesn't get sent with every HTTP request, so it can be a better option for client-side storage. b) cookie is set and acces_token can be read (is at least a readable JWT token). Why avoiding LocalStorage for tokens is the wrong solution Otherwise, we'll save the item as is. Doesn't need to be used in an ultra high performance app. How to Save Data with Local Storage in React - Code-Boost Next time you're faced with having to make a React component's state persistent across a browser refresh, remember to: Analyze your current situation to check if using Local Storage together with useEffect hook is appropriate; Get a unique key to store your component state in order to avoid collisions at the Local Storage In this article, we investigate how an attacker can bypass even the most advanced mechanisms to obtain access tokens through an XSS attack. [1:48] To get that value out, let's say scratchpad.value equals localstorage.get-item-and-get-the-notes.