Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3.  
  4. class AddNumberComponent extends Component {
  5.     state = {
  6.         numero: 0,
  7.     }
  8.  
  9.     addNumber = () => this.setState({ numero: this.state.numero + 1})
  10.  
  11.     multiplyNumberBy2 = () => {
  12.       const { numero } = this.state;
  13.       return numero * 2;
  14.     }
  15.  
  16.     render(){
  17.     const { numero } = this.state;
  18.     const { getCurrentNumber } = this.props;
  19.     return(
  20.         <div>
  21.             <p style={{ color: 'black'}}>{numero}</p>
  22.             <button
  23.                 type="button"
  24.                 onClick={this.addNumber}
  25.                 >
  26.                 Click
  27.             </button>
  28.             <p>Numero * 2: {this.multiplyNumberBy2()}</p>
  29.  
  30.             <button
  31.                 type="button"
  32.                 onClick={()=> getCurrentNumber(numero, "hola papá")}
  33.                 >
  34.                 Enviar numero al padre
  35.             </button>
  36.         </div>
  37.     );
  38.     }
  39. }
  40.  
  41. AddNumberComponent.propTypes = {
  42.     getCurrentNumber: PropTypes.func.isRequired,
  43. };
  44.  
  45. export default AddNumberComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement