SHARE
TWEET

button click

nisalucky Jul 17th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3.  
  4. import "./styles.css";
  5.  
  6. class App extends React.Component {
  7.   render() {
  8.     return (
  9.       <div>
  10.         <Counter />
  11.         <Counter />
  12.         <Counter />
  13.       </div>
  14.     );
  15.   }
  16. }
  17.  
  18. class Header extends React.Component {
  19.   render() {
  20.     return (
  21.       <div>
  22.         <h1>{this.props.name}</h1>
  23.       </div>
  24.     );
  25.   }
  26. }
  27. // props -> properties
  28.  
  29. class Counter extends React.Component {
  30.   state = {
  31.     angka: 0
  32.   };
  33.   naik = () => {
  34.     this.setState({
  35.       angka: this.state.angka + 1
  36.     });
  37.   };
  38.  
  39.   turun = () => {
  40.     this.setState({
  41.       angka: this.state.angka - 1
  42.     });
  43.   };
  44.  
  45.   render() {
  46.     return (
  47.       <div>
  48.         <h1>{this.state.angka}</h1>
  49.         <button onClick={this.naik}>+</button>
  50.         <button onClick={this.turun}>-</button>
  51.       </div>
  52.     );
  53.   }
  54. }
  55. const rootElement = document.getElementById("root");
  56. ReactDOM.render(<App />, rootElement);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top