proxy-based Twister client written with react-js
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Julian Steinwachs c2cf8a0177 cache is now automatically trimmed by 2 weeks 10 years ago
..
LICENSE cache is now automatically trimmed by 2 weeks 10 years ago
README.md cache is now automatically trimmed by 2 weeks 10 years ago
index.js cache is now automatically trimmed by 2 weeks 10 years ago
package.json cache is now automatically trimmed by 2 weeks 10 years ago

README.md

react-mixin-safe-state-change

npm version npm downloads

React mixin which sets or replaces state only when it is safe to do so.

Motivation

When processing the response of an asynchronous request, it might not be safe to call setState or replaceState, because the component might no longer be mounted.

Install

npm install react-mixin-safe-state-change

Usage

var safeStateChangeMixin = require('react-mixin-safe-state-change');

React.createClass({
  mixins: [safeStateChangeMixin]

  someCallback: function(newValue) {
    if (!this.setStateSafe({value: newValue})) {
      console.warn('Could not set the state.');
    }

    // or

    if (!this.replaceStateSafe({value: newValue})) {
      console.warn('Could not replace the state.');
    }
  }
});