Skip to content

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

@Esanayobami

Description

@Esanayobami

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions