-
Notifications
You must be signed in to change notification settings - Fork 61
/
Ref.js
42 lines (34 loc) · 902 Bytes
/
Ref.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
import React from 'react';
import {DebounceInput} from '../src';
export class Ref extends React.Component {
state = {
value: '',
key: undefined
};
render() {
const {
value,
key
} = this.state;
return (
<div>
<div className="config">
<label className="label">
<button type="button" onClick={() => this.ref.focus()}>Focus, please</button>
</label>
<label className="label">
<button type="button" onClick={() => this.ref.blur()}>Blur, please</button>
</label>
</div>
<DebounceInput
inputRef={ref => {
this.ref = ref;
}}
onChange={e => this.setState({value: e.target.value})}
onKeyDown={e => this.setState({key: e.key})} />
<p>Value: {value}</p>
<p>Key pressed: {key}</p>
</div>
);
}
}