Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import cx from 'classnames';
  2. import { Component } from 'react';
  3.  
  4. export default class Counter extends Component {
  5. constructor (props) {
  6. super(props);
  7. this.state = {
  8. count: 42
  9. };
  10.  
  11. this.increment = this.increment.bind(this);
  12.  
  13. }
  14.  
  15. increment () {
  16. this.setState((state, props) => ({
  17. count: state.count + 1
  18. }));
  19. }
  20.  
  21. render() {
  22. return (
  23. <>
  24. <div>
  25. <h2>Counter</h2>
  26. <h2 className="counter">{this.state.count}</h2>
  27. <button className="counter-button" onClick={this.increment}>Click</button>
  28. </div>
  29. <style>{`
  30. .counter-button {
  31. font-size: 1rem;
  32. padding: 5px 10px;
  33. color: #585858;
  34. }
  35. `}</style>
  36. </>
  37. );
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement