NullVoxPopuli / react-state-helpers

component state helpers for react to help reduce boilerplate and to not rely on redux for everything
25 stars 4 forks source link

Add some @ember-decorators inspired decorators #12

Open NullVoxPopuli opened 6 years ago

NullVoxPopuli commented 6 years ago

to maybe eliminate the need for setState all together.

// something like:
function tracked(target, name, descriptor) {
  // logic
  return {
    ...descriptor,
    get() {
      descriptor.value;
    }
    set(val) {
      this.setState(name, val);
    }
  }
}

class Whatever extends React.Component {
    @tracked fromDate;
}
NullVoxPopuli commented 6 years ago

this is pretty legit: https://codesandbox.io/s/j24oo3z823

state updates asyncily by doing this.property = value

image

NullVoxPopuli commented 6 years ago

completly omitting the class property value and keeping everything in state: image