mbasso / react-decoration

A collection of decorators for React Components
MIT License
631 stars 24 forks source link

[Feature] Provider a state property decorator. #15

Open Moln opened 4 years ago

Moln commented 4 years ago

General Information

Description

For simply use state properties.

@component()
export default class Hello extends Component<{name: string}, any> {
  @state()
  name = this.props.name;

  @state()
  age: number = 20;

  render() {
    console.log("render hello");
    return (
      <div>
        Hello {this.name}, age: {this.age}
        <br />
        <button onClick={this.handleClick}>Incr age</button>
      </div>
    );
  }

  private handleClick = () => {
    this.age++;
  };
}

Steps to reproduce

https://codesandbox.io/s/provider-a-state-property-decorator-r8yh3

mbasso commented 4 years ago

Hi @Moln, cool, thank you for sharing! I am a little bit busy at the moment and I cannot implement it soon. Are you interested in following through with a PR? Otherwise, I will do it when it will be possible 😄