-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathApp.js
More file actions
60 lines (50 loc) · 1.24 KB
/
App.js
File metadata and controls
60 lines (50 loc) · 1.24 KB
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
import React from "react";
import ReactDOM from "react-dom";
import Clipboard from "react-clipboard";
class Mouse extends React.Component {
handleMove = ({ clientX, clientY }) => {
this.props.onMove({ x: clientX, y: clientY });
};
componentDidMount() {
document.addEventListener("mousemove", this.handleMove);
}
componentWillUnmount() {
document.removeEventListener("mousemove", this.handleMove);
}
render() {
return null;
}
}
class App extends React.Component {
state = {
pos: {
x: 0,
y: 0
},
copied: false
};
handleCopy = () => {
clearTimeout(this.timer);
this.setState({ copied: true });
this.timer = setTimeout(() => this.setState({ copied: false }), 1000);
};
handleMove = pos => {
this.setState({ pos });
};
render() {
const { pos, copied } = this.state;
const value = JSON.stringify(pos, null, " ");
return (
<div>
<Mouse onMove={this.handleMove} />
<p>Press Cmd + C to copy mouse position</p>
<pre>
({pos.x},{pos.y})
</pre>
<Clipboard value={value} onCopy={this.handleCopy} />
{copied && <p>copied</p>}
</div>
);
}
}
ReactDOM.render(<App />, document.querySelector("#app"));