Created
July 23, 2018 02:11
-
-
Save qzm/ec7d0b7d7a3cdc65011c7f772268f62b to your computer and use it in GitHub Desktop.
React setStateAsync change thunk to promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component as OriginComponent } from 'react'; | |
export default class Component extends OriginComponent { | |
setStateAsync(nextState) { | |
return new Promise((resolve, reject) => { | |
try { | |
this.setState(nextState, resolve); | |
} catch (error) { | |
reject(error); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PureComponent as OriginPureComponent } from 'react'; | |
export default class PureComponent extends OriginPureComponent { | |
setStateAsync(nextState) { | |
return new Promise((resolve, reject) => { | |
try { | |
this.setState(nextState, resolve); | |
} catch (error) { | |
reject(error); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment