Created
March 1, 2017 17:13
-
-
Save almapase/995a391defd05bf08f8171a8633b4939 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/biziyo
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script src="https://fb.me/react-with-addons-15.1.0.js"></script> | |
<script src="https://fb.me/react-dom-15.1.0.js"></script> | |
<script id="jsbin-javascript"> | |
class Empleado extends React.Component { | |
render () { | |
return ( | |
React.createElement("li", null, this.props.nombre, " - ", this.props.email) | |
); | |
} | |
} | |
class ListaEmpleados extends React.Component { | |
render () { | |
return ( | |
React.createElement("div", null, | |
React.createElement("ul", null, | |
this.props.empleados.map( | |
empleado => { | |
return ( | |
React.createElement(Empleado, { | |
key: empleado.id, | |
nombre: empleado.nombre, | |
email: empleado.email} | |
) | |
); | |
} | |
) | |
), | |
React.createElement("form", {onSubmit: this.props.onAddEmployee}, | |
React.createElement("input", {type: "text", placeholder: "Id", name: "id"}), | |
React.createElement("input", {type: "text", placeholder: "Nombre", name: "nombre"}), | |
React.createElement("input", {type: "email", placeholder: "Email", name: "email"}), | |
React.createElement("input", {type: "submit", value: "Guardar"}) | |
) | |
) | |
); | |
} | |
} | |
class App extends React.Component { | |
constructor(){ | |
super(); | |
this.state = { | |
empleados: [ | |
{id: 1, nombre: "pepe", email: "[email protected]"}, | |
{id: 2, nombre: "juanito", email: "[email protected]"} | |
] | |
}; | |
} | |
handleOnAddEmployee (event) { | |
event.preventDefault(); | |
let empleado = { | |
id: event.target.id.value, | |
nombre: event.target.nombre.value, | |
email: event.target.email.value | |
}; | |
this.setState({ | |
empleados: this.state.empleados.concat([empleado]) | |
}); | |
} | |
render () { | |
return ( | |
React.createElement(ListaEmpleados, { | |
empleados: this.state.empleados, | |
onAddEmployee: this.handleOnAddEmployee.bind(this)} | |
)); | |
} | |
} | |
ReactDOM.render(React.createElement(App, null), document.getElementById('app')); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">class Empleado extends React.Component { | |
render () { | |
return ( | |
<li>{this.props.nombre} - {this.props.email}</li> | |
); | |
} | |
} | |
class ListaEmpleados extends React.Component { | |
render () { | |
return ( | |
<div> | |
<ul> | |
{ | |
this.props.empleados.map( | |
empleado => { | |
return ( | |
<Empleado | |
key={empleado.id} | |
nombre={empleado.nombre} | |
email={empleado.email} | |
/> | |
); | |
} | |
) | |
} | |
</ul> | |
<form onSubmit={this.props.onAddEmployee}> | |
<input type="text" placeholder="Id" name="id" /> | |
<input type="text" placeholder="Nombre" name="nombre" /> | |
<input type="email" placeholder="Email" name="email" /> | |
<input type="submit" value="Guardar" /> | |
</form> | |
</div> | |
); | |
} | |
} | |
class App extends React.Component { | |
constructor(){ | |
super(); | |
this.state = { | |
empleados: [ | |
{id: 1, nombre: "pepe", email: "[email protected]"}, | |
{id: 2, nombre: "juanito", email: "[email protected]"} | |
] | |
}; | |
} | |
handleOnAddEmployee (event) { | |
event.preventDefault(); | |
let empleado = { | |
id: event.target.id.value, | |
nombre: event.target.nombre.value, | |
email: event.target.email.value | |
}; | |
this.setState({ | |
empleados: this.state.empleados.concat([empleado]) | |
}); | |
} | |
render () { | |
return ( | |
<ListaEmpleados | |
empleados={this.state.empleados} | |
onAddEmployee={this.handleOnAddEmployee.bind(this)} | |
/>); | |
} | |
} | |
ReactDOM.render(<App />, document.getElementById('app'));</script></body> | |
</html> |
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 Empleado extends React.Component { | |
render () { | |
return ( | |
React.createElement("li", null, this.props.nombre, " - ", this.props.email) | |
); | |
} | |
} | |
class ListaEmpleados extends React.Component { | |
render () { | |
return ( | |
React.createElement("div", null, | |
React.createElement("ul", null, | |
this.props.empleados.map( | |
empleado => { | |
return ( | |
React.createElement(Empleado, { | |
key: empleado.id, | |
nombre: empleado.nombre, | |
email: empleado.email} | |
) | |
); | |
} | |
) | |
), | |
React.createElement("form", {onSubmit: this.props.onAddEmployee}, | |
React.createElement("input", {type: "text", placeholder: "Id", name: "id"}), | |
React.createElement("input", {type: "text", placeholder: "Nombre", name: "nombre"}), | |
React.createElement("input", {type: "email", placeholder: "Email", name: "email"}), | |
React.createElement("input", {type: "submit", value: "Guardar"}) | |
) | |
) | |
); | |
} | |
} | |
class App extends React.Component { | |
constructor(){ | |
super(); | |
this.state = { | |
empleados: [ | |
{id: 1, nombre: "pepe", email: "[email protected]"}, | |
{id: 2, nombre: "juanito", email: "[email protected]"} | |
] | |
}; | |
} | |
handleOnAddEmployee (event) { | |
event.preventDefault(); | |
let empleado = { | |
id: event.target.id.value, | |
nombre: event.target.nombre.value, | |
email: event.target.email.value | |
}; | |
this.setState({ | |
empleados: this.state.empleados.concat([empleado]) | |
}); | |
} | |
render () { | |
return ( | |
React.createElement(ListaEmpleados, { | |
empleados: this.state.empleados, | |
onAddEmployee: this.handleOnAddEmployee.bind(this)} | |
)); | |
} | |
} | |
ReactDOM.render(React.createElement(App, null), document.getElementById('app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment