localStorage.service.js 398 B

123456789101112
  1. import {pizzaList} from '../data/pizzaList.js'
  2. export const setPizzasListToLS = () => {
  3. localStorage.setItem('pizzas', JSON.stringify(pizzaList));
  4. }
  5. // localStorage
  6. export const getPizzasListFromLS = () => {
  7. const pizzasListFromLS = JSON.parse(localStorage.getItem('pizzas'));
  8. if (pizzasListFromLS) {
  9. pizzasListFromLS.forEach((pizza, i) => pizzaList[i] = pizza);
  10. }
  11. }