Skip to content

Suggestion: make allStudents a class so you can move localStorage.setItem() into lifecycle method #31

@tomduggan85

Description

@tomduggan85

localStorage.setItem('students', JSON.stringify(users.students));

Right now, allStudents is a functional component and it's render has a side effect behavior - it is calling localStorage.setItem. I would suggest turning this functional component into a class component, so that you can move the localStorage.setItem call into componentDidMount. This would be better because localStorage.setItem would only be called once, when the component is created, instead of being called every time the component is rendered (which can potentially be a lot of calls), which could make your render slow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions