Skip to content

Instantly share code, notes, and snippets.

@furenku
Last active June 12, 2018 02:26
Show Gist options
  • Select an option

  • Save furenku/8d3cfc9abae0330825c6781ffae16a7f to your computer and use it in GitHub Desktop.

Select an option

Save furenku/8d3cfc9abae0330825c6781ffae16a7f to your computer and use it in GitHub Desktop.
componente React
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;
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