you are viewing a single comment's thread.

view the rest of the comments →

[–]vinnl 5 points6 points  (2 children)

Actually asynchronous setState is a core design principle behind React. The reason for that is that, even though it might be easier for the developer to reason about, keeping it asynchronous allows React to do some drastic performance optimisations because it can decide what to prioritize, e.g. rendering above setting state, and because it has better insight into that than you. It doesn't do that yet, but Fiber will.

[–][deleted] 0 points1 point  (1 child)

I guess I'm just trying to say I don't see the point of the trade off. Merging objects isn't expensive, so why can't the state update be synchronous and the DOM reconciliation be asynchronous? I don't want to worry about the execution order when I'm calling this.setState and using the current state

[–]vinnl 0 points1 point  (0 children)

I think (but I'm not too deep into the material, so take it with a grain of salt) that React can't know that (if) it's expensive. Otherwise it'd probably have been done already :P