Skip to content

the-road-to-learn-react/react-alternative-class-component-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-alternative-class-component-syntax

Build Status Slack Greenkeeper badge

React Class Components can be made much more concise using the class field declarations. You can initialize local state without using the constructor and declare class methods by using arrow functions without the extra need to bind them.

class Counter extends Component {
  state = { value: 0 };

  handleIncrement = () => {
    this.setState(prevState => ({
      value: prevState.value + 1
    }));
  };

  handleDecrement = () => {
    this.setState(prevState => ({
      value: prevState.value - 1
    }));
  };

  render() {
    return (
      <div>
        {this.state.value}

        <button onClick={this.handleIncrement}>+</button>
        <button onClick={this.handleDecrement}>-</button>
      </div>
    )
  }
}

Installation

  • git clone [email protected]:the-road-to-learn-react/react-alternative-class-component-syntax.git
  • cd react-alternative-class-component-syntax
  • npm install
  • npm start
  • visit http://localhost:8080

About

An alternative/future way of React Class Component with Class Field Declarations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published