Accepted answer

Once handleClick has completed, is a re-render guaranteed to happen immediatelly handleClick has done running? I mean literally immediately, like synchronously immediately

For certain events, including click, React guarantees that the component will be re-rendered before another event can occur. (This isn't the case for other events like mousemove.) You can find which events are which here. The current terminology seems to be that DiscreteEvents are the ones for which this guarantee exists, and the UserBlockingEvents are the ones for which it isn't guaranteed. It may well be that in the current implementation that means it's done synchronously at the end of the event handling┬╣, but I think the guarantee is less specific than that.

I learned this from Dan Abramov on Twitter (he used the older terminology for the events).

┬╣ Edit: and in fact, in his answer Joseph D. points to a comment by Dan Abramov saying that it is, for now, but also saying "This is implementation detail and may change in future versions".


is it guaranteed that a re-render will occur immediately (synchronously) after that completion of the handler?

Yes for onClick.

As pointed by Dan Abramov:

React batches all setStates done during a React event handler, and applies them just before exiting its own browser event handler.

Related Query

More Query from same tag