Created
June 19, 2019 09:02
-
-
Save munkacsitomi/2e7971947051efe2cbf929ff04b1cc43 to your computer and use it in GitHub Desktop.
How to use data from local storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instead of converting string to boolean | |
const isRetention = localStorage.getItem('is_retention') === 'true'; | |
// Parsing the JSON is better solution | |
const isRetention = JSON.parse(localStorage.getItem('is_retention')); | |
// Or create a helper function to parse the item | |
const getLocalStorageItem = item => JSON.parse(localStorage.getItem(item)); | |
const isRetention = getLocalStorageItem('is_retention'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment