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.