reactjs-simple-counter-01

In this example below you will see how to do a reactjs-simple-counter-01 with some HTML / CSS and Javascript

This is my first react example.

Thumbnail
This awesome code was written by Shawn Mahoney, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Shawn Mahoney ©
  • HTML
  • CSS
  • JavaScript
        <!-- 
REFERENCE:
https://medium.freecodecamp.org/how-to-write-your-first-react-js-component-d728d759cabc 
-->

<div id="root1">
  <!-- This div's content will be managed by React. -->
</div>
    

/*Downloaded from https://www.codeseek.co/smahoney94/reactjs-simple-counter-01-QxKKEM */
        
    

/*Downloaded from https://www.codeseek.co/smahoney94/reactjs-simple-counter-01-QxKKEM */
        class Button extends React.Component {
  state = { counter: 1 };
  
  handleClick = () => {
    this.setState((prevState) => ({
      counter: prevState.counter + 1 
    }));
  };
  
  render() {
    return (
      <button onClick={this.handleClick}>
        {this.state.counter}
      </button>
    );
  }
}

ReactDOM.render(<Button />, document.getElementById('root1'));
    

Comments