I have a Gatsby app where I am creating a little shopping cart. In order to make the data persist whenever a user clicks on add to cart, I want to use local storage. I use the below code for this
import React from 'react';
export default function OrderItem() {
const addToCart = (selectedItem) => {
localStorage.setItem('cartItems', selectedItem);
};
return (
<div>
<button onClick={addToCart}>Add </button>
</div>
);
}
But this gives me a localStorage.setItem is not a function error.
Anyone have any idea on why this might be happening?
