Skip to content

Do not call setState() from render #29

@tomduggan85

Description

@tomduggan85

this.isStudent() is called from render and can call setState (if the student is not found). In general, render() should not have side effects like that and should only be returning jsx, not doing any other work. The problem here is that setState() itself calls render(), so if render calls setState, there are extra renders happening and it's possible to create an infinite loop of rendering.

I think you could refactor this to move the isStudent() check into componentDidMount() possibly.

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