1.1.1 • Published 5 years ago

@tiencoffee/reactive v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

@tiencoffee/reactive

Change React state directly without setState, just like Vue.

Download

Installation

In a browser:

<script src="reactive.js"></script>

or using a CDN

<script src="https://unpkg.com/@tiencoffee/reactive"></script>

Using npm:

$ npm i @tiencoffee/reactive

Usage

  • Just inherit the Reactive class instead of React.Component. Now, you can change the state directly. In addition, the methods will automatically be bound. Example:
class Foo extends Reactive {
  constructor(props) {
    super(props)

    this.state = {
      bar: "qux",
      baz: "quux"
      arr: [1, 2, 3]
    }
  }

  onClick() {
    console.log(this.state.baz)
  }

  componentDidMount() {
    this.state.bar = 16
    this.state.arr.push(4, 5, 6)
    this.state.arr.pop()
    this.state.arr.reverse()
    delete this.state.bar
    this.state.fred = {a: 50, b: null, c: 2}
  }

  render() {
    return (
      <div onClick={this.onClick}>
        {this.state.baz}
      </div>
    )
  }
}
1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago