June
June

Reputation: 2217

Does codes below the `setState()` get executed in React?

React's official document says that React components will automatically start to re-render component on setState() calls. Does that mean any codes below the setState() won't get executed ever?

Upvotes: 1

Views: 278

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47222

Yes, code below this.setState will always be executed unless you return this.setState of course.

However a thing to note with calls to this.setState is not guaranteed to be synchronous, meaning calls can and will be batched if React deems necessary.

Complimentary JSFiddle

React#setState docs

Upvotes: 3

Related Questions