Skip to content

Reactjs higher order component to easily avoid the unsafe setState

Notifications You must be signed in to change notification settings

madeinfree/with-safe-set-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React with safe setState higher order component

Reactjs higher order component to easily avoid the unsafe setState

Install

$ npm install with-safe-set-state

Usage

Box.jsx

import React, { Component } from 'react';
import { withSafeSetState } from 'with-safe-set-state';

class Box extends Component {
  constructor() {
    super();
    this.state = { info: 'Default' };
  }
  _onClick() {
    setTimeout(() => {
      this.setState(_ => ({
        info: 'OK'
      }));
    }, 1000);
  }
  render() {
    return <button onClick={this._onClick.bind(this)}>Click</button>;
  }
}

export default withSafeSetState(Box);

License

MIT © Whien

About

Reactjs higher order component to easily avoid the unsafe setState

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published