Skip to content
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

Add Promise support to setState() . #9989

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Add Promise support to setState() .

See #2642
  • Loading branch information...
peacechen committed Jun 16, 2017
commit b5da0b3aff4ecbbdff4ba264f2f6ee33afeb4899
@@ -64,7 +64,26 @@ ReactComponent.prototype.setState = function(partialState, callback) {
'setState(...): takes an object of state variables to update or a ' +
'function which returns an object of state variables.',
);
let callbackPromise;
if (!callback) {
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.reject = reject;
this.resolve = resolve;
});
}
}
callbackPromise = new Deferred();
callback = () => {
callbackPromise.resolve();
};
}
this.updater.enqueueSetState(this, partialState, callback, 'setState');

if (callbackPromise) {
return callbackPromise.promise;
}
};

/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.