react icon indicating copy to clipboard operation
react copied to clipboard

Illogical architecture of setState

Open shubik opened this issue 11 years ago • 2 comments

Dear React developers and community. Can anyone please explain to me why React throws a hard error if I use setState (or anything that entails setting new state, e.g. replaceState) if setState should work ONLY on a mounted component? If it never works with unmounted component, than what's the harm in using console.warn instead? Because in ALL our code we must use this.isMounted() && this.setState() — which is completely redundant.

Can you please provide an explanation for this? Can you allow using a certain init option for not throwing this error?

shubik avatar Jan 09 '15 18:01 shubik

https://github.com/facebook/react/issues/2787#issuecomment-68738793

gaearon avatar Jan 09 '15 19:01 gaearon

Going to close this out and just refer to that other issue. Let me know if there isn't enough there to answer your questions and give you an idea of the direction we're heading.

zpao avatar Jan 09 '15 19:01 zpao