-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHandler.js
63 lines (49 loc) · 1.02 KB
/
EventHandler.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Poner un controlador de eventos en una clase de componente
// pasar funciones como props. Es especialmente común pasar las funciones del controlador de eventos .
// Explample.js
import React from 'react';
class Example extends React.Component {
handleEvent() {
alert(`I am an event handler.
If you see this message,
then I have been called.`);
}
render() {
return (
<h1 onClick={this.handleEvent}>
Hello world
</h1>
);
}
}
// Talker.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Button } from './Button';
class Talker extends React.Component {
talk() {
let speech = '';
for (let i = 0; i < 10000; i++) {
speech += 'blah ';
}
alert(speech);
}
render() {
return <Button />;
}
}
ReactDOM.render(
<Talker />,
document.getElementById('app')
);
// Button.js
import React from 'react';
export class Button extends React.Component {
render() {
return (
<button>
Click me!
</button>
);
}
}