with-thenable-setstate
HOC to add a thenable setState to your React components.
Installation
npm i with-thenable-setstate
Usage
import * as React from 'react'
import withThenableSetState from 'with-thenable-setstate'
// `require` also works:
// const withThenableSetState = require('with-thenable-setstate')
class Foo extends React.Component {
state = { a: 0 }
// async/await example
async something () {
try {
await this.thenableSetState({ a: 1 })
await doSomethingElseNow()
} catch (e) {
// handle e
}
}
// promise syntax example
somethingElse () {
this.thenableSetState({ a: 2 })
.then(doSomethingElseNow)
.catch((e) => {
// handle e
})
}
}
export default withThenableSetState(Foo)