Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

store data to the browser’s localStorage

export const setToLS = (key, value) => {
  window.localStorage.setItem(key, JSON.stringify(value));
}

export const getFromLS = key => {
  const value = window.localStorage.getItem(key);

  if (value) {
    return JSON.parse(value);
  }
}
Source by css-tricks.com #
 
PREVIOUS NEXT
Tagged: #store #data #localStorage
ADD COMMENT
Topic
Name
8+3 =