-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shallow renderer: pass component instance to setState updater as this
#12784
Conversation
@@ -298,7 +298,7 @@ class Updater { | |||
const currentState = this._renderer._newState || publicInstance.state; | |||
|
|||
if (typeof partialState === 'function') { | |||
partialState = partialState(currentState, publicInstance.props); | |||
partialState = partialState.call(publicInstance, currentState, publicInstance.props); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run yarn prettier
to reformat this file and CI should pass! 😄
It's kinda weird that we support that btw. I wonder why. |
One possible usecase is to have updaters as instance methods:
Of course, |
Yeah, the problem is that if you need something instance-y in the updater usually it means the code is wrong. Anyway, thanks for fixing. |
…s` (#12784) * Shallow renderer: pass component instance to setState updater as `this` * Run prettier
This makes react-test-renderer behaviour aligned with one of react-reconciler, see
react/packages/react-reconciler/src/ReactUpdateQueue.js
Line 413 in b548b3c