react-state-promise

1.3.3 • Public • Published

react-state-promise

get a Promise from setState instead of using the idiot callback from facebook!

setState

import setState from 'react-state-promise';

class YourComponent extends Component {

  test() {
    setState(this, {
        running: true,
      })
      .then(({state, lastState}) => {
        if(state.running && !lastState.running) { .... }
      });
  }


  easy() {
    setState(this, {
        easy: true,
      })
      .then(() => {
        ......
      });
  }
}

you can also :

getNextState

import { getNextState } from 'react-state-promise';
....

getNextState(this)

and

willChange

import { willChange } from 'react-state-promise';
....

willChange(this, {aStatePart: true})

Package Sidebar

Install

npm i react-state-promise

Weekly Downloads

13

Version

1.3.3

License

MIT

Last publish

Collaborators

  • soenkekluth