-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-comp.js
47 lines (43 loc) · 1.36 KB
/
app-comp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const Note = ({ text }) => {
return <div>
{text}
<button onClick={(event) => event.target.parentNode.remove()}>Eliminar</button>
</div>
};
class App extends React.Component {
constructor(props) {
super(props);
console.log(props);
this.state = {
text: props.text,
notes: props.notes || []
};
this.addCurrentNote = this.addCurrentNote.bind(this);
}
addCurrentNote() {
this.setState({ notes: [...this.state.notes, this.state.text] });
this.setState({ text: "" });
};
render() {
return (
<div id="container">
<h1 id="title-js">Bienvenido a <em>React-DOM con Components</em></h1>
<h2>Notas: {this.state.text}</h2>
<div className="fooDiv">
<input
value={this.state.text}
onChange={ev => this.setState({
text: ev.target.value
})}
/>
<button onClick={this.addCurrentNote}>Agregar</button>
</div>
{this.state.notes.map((note, i) => <Note key={i} text={note} />)}
</div>
);
};
}
ReactDOM.render(<App
text="Soy un text pasado por props"
num='42'
/>, document.getElementById("app"));