react_controlled_inputs icon indicating copy to clipboard operation
react_controlled_inputs copied to clipboard

error in the content "<Content />" : Uncaught TypeError: Cannot read properties of null (reading 'filter')

Open Esanayobami opened this issue 2 years ago • 0 comments

the "items" state is null and that you're trying to call the filter method on it. This error occurs because the JSON.parse method returns null if there is no data stored in local storage.

To resolve this issue, you can check if the value of items is null and set it to an empty array if it is:

const [items, setItems] = useState( JSON.parse(localStorage.getItem("shoppinglist")) || [] );

by : chatGpt

Esanayobami avatar Feb 08 '23 23:02 Esanayobami