Guest User

Untitled

a guest
Jul 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. // State
  2. class App extends React.Component {
  3. constructor(props) {
  4. super(props);
  5.  
  6. this.state = {
  7. contador: 0
  8. }
  9.  
  10. }
  11.  
  12. onClickHandler() {
  13. this.setState({
  14. contador: this.state.contador + 1
  15. })
  16. }
  17.  
  18. render() {
  19. return(
  20. <div>
  21. <Contador valor={this.state.contador} />
  22. <Button label="Add" onClick={() => this.onClickHandler()} />
  23. <Button label="Escreve no console" onClick={ () => console.log('ok')} />
  24. </div>
  25. );
  26. }
  27. }
  28.  
  29. //<button onClick={() => this.onClickHandler()}>Add</button>
  30.  
  31. const Button = (props) => {
  32. return(
  33. <div>
  34. <button onClick={() => props.onClick()}>{props.label}</button>
  35. </div>
  36. );
  37. }
  38.  
  39. const Contador = (props) => {
  40. return (
  41. <div>
  42. <h1>{props.valor}</h1>
  43. </div>
  44. );
  45. }
  46. // class Contador extends React.Component {
  47.  
  48. // constructor() {
  49. // super()
  50. // }
  51.  
  52. // render() {
  53. // return(
  54. // <div>
  55. // <h1>{this.props.valor}</h1>
  56. // </div>
  57. // );
  58. // }
  59. // }
  60.  
  61. ReactDOM.render(
  62. <App />,
  63. document.getElementById('app')
  64. )
Add Comment
Please, Sign In to add comment