Skip to content

docs: clarify this binding in setState callback#8414

Open
Assamee wants to merge 1 commit intoreactjs:mainfrom
Assamee:docs/issue-8314-setstate-callback
Open

docs: clarify this binding in setState callback#8414
Assamee wants to merge 1 commit intoreactjs:mainfrom
Assamee:docs/issue-8314-setstate-callback

Conversation

@Assamee
Copy link
Copy Markdown

@Assamee Assamee commented Apr 17, 2026

Fixes #8314

Summary
The legacy Component API docs for setState don't mention that React automatically binds this for the optional callback parameter. This usually leads to developers writing unnecessary arrow functions or using manual .bind(this) because they (rightly) assume standard JS rules apply.

I've updated the callback description to clarify that React handles this binding internally rather than leaving it as an undocumented behaviour.

Testing
I verified this in a local Vite environment with a standard Class Component. I used a function() (not an arrow function) as the callback and confirmed that this correctly points to the component instance. I also verified that I could access this.state and this.props inside the callback without any manual binding.

@github-actions
Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation should state that React preserves setState callback this context

1 participant