Last active
June 12, 2018 02:26
-
-
Save furenku/8d3cfc9abae0330825c6781ffae16a7f to your computer and use it in GitHub Desktop.
componente React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import PropTypes from 'prop-types'; | |
| function MiPrimerComponente( props ) { | |
| return ( | |
| <h3> | |
| {props.texto} | |
| </h3> | |
| ) | |
| } | |
| function Persona( props ) { | |
| return ( | |
| <p> | |
| {props.apellido}, {props.nombres}. | |
| {props.edad} años. | |
| <b> | |
| Profesión: {props.profesion} | |
| </b> | |
| </p> | |
| ); | |
| } | |
| class App extends Component { | |
| render() { | |
| return ( | |
| <div> | |
| <MiPrimerComponente texto="abc"/> | |
| <MiPrimerComponente texto="def"/> | |
| <MiPrimerComponente texto="gih"/> | |
| <Persona apellido="Pérez" nombres="Carlos" edad="44" profesion="programador"/> | |
| <Persona apellido="Torres Jiménez" nombres="Claudia" edad="24" profesion="funcionaria"/> | |
| <Contador inicio={Math.round(Math.random()*20)} incremento={10} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Contador extends Component { | |
| constructor( props ) { | |
| super( props ); | |
| // definimos nuestro estado: | |
| this.state = { | |
| numeroClicks: this.props.inicio | |
| } | |
| } | |
| render() { | |
| return ( | |
| <div onClick={ () => this.incrementar() }> | |
| Número de clicks: {this.state.numeroClicks} | |
| </div> | |
| ) | |
| } | |
| incrementar() { | |
| this.setState({ | |
| numeroClicks: this.state.numeroClicks + this.props.incremento | |
| }) | |
| } | |
| } | |
| Contador.propTypes = { | |
| inicio: PropTypes.number | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment