You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation should state that React preserves setState callback this context #8314
I just recently found out that setState's callback calls with the correct this context per this line in the React source. Nowhere in the documentation is it stated that React internally calls callbacks with context. This should be made clear as many assume it doesn't, leading to unnecessary measures such as arrow functions, explicit binding, etc.
The lack of explicit documentation also creates confusion with other things that do require binding, such as traditional class methods used as event handlers.
I've submitted a PR (#8414) for this. I verified the behaviour in a local environment and confirmed you're right, this context is preserved without any manual binding. Good catch on the confusion with event handlers, it's definitely worth clarifying.
Activity
Assamee commentedon Apr 17, 2026
I've submitted a PR (#8414) for this. I verified the behaviour in a local environment and confirmed you're right,
thiscontext is preserved without any manual binding. Good catch on the confusion with event handlers, it's definitely worth clarifying.