Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Created June 19, 2019 09:02
Show Gist options
  • Save munkacsitomi/2e7971947051efe2cbf929ff04b1cc43 to your computer and use it in GitHub Desktop.
Save munkacsitomi/2e7971947051efe2cbf929ff04b1cc43 to your computer and use it in GitHub Desktop.
How to use data from local storage
// 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