Skip to content

Prevent a function to be called from within render #5302

@joIivier

Description

@joIivier

You have a warning in React if you call setState() from within a render method, with the check ReactCurrentOwner.current == null. I would like to add this check to other methods of my project because they also trigger rerender or are too expensive.
The issue I have is that ReactCurrentOwner is not exposed by React, so how can I achieve that? The current solution I have in mind is to check from the stack trace but that's a lot more expensive than your check so I would prefer if there was something equivalent to your code but from outside React.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions