Hacker News new | past | comments | ask | show | jobs | submit login
SetState() Gate: Navigating React SetState() Behavior Confusion (medium.com/javascript-scene)
3 points by ericelliott on March 19, 2017 | hide | past | favorite | 1 comment



> I still bump into rough edges now and then when I’m dealing with forms or DOM element coordinates because, when you use setState(), you have to deal with the component lifecycle directly.

Do you have an example of this? Why do you have to deal with the component lifecycle directly because of setState?

Agreed that it's not intuitive from the API signature that setState is an asynchronous operation, and this can trip up new devs the first time. This is a recognized and non-controversial point of confusion. I've never seen this be a substantial issue in real life, though. The article mentions having to frequently hack around setState's behavior, but I don't think I've seen this in any of the codebases I've worked in. I've also seen developers that are new to react get confused by this behavior initially, but never repeatedly after the first time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: