summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-06-30 20:23:50 +0300
committerAndrej Mihajlov <and@codeispoetry.ru>2017-06-30 23:58:44 +0300
commit7d26c8dd0c74918dc8d3096cf820d77f1664123d (patch)
tree07b74ffa7b31904bc09aea75f4e2562639c1b9fd
parentc237f34ae776aa2abfea26270fba7948fc54afc5 (diff)
downloadmullvadvpn-7d26c8dd0c74918dc8d3096cf820d77f1664123d.tar.xz
mullvadvpn-7d26c8dd0c74918dc8d3096cf820d77f1664123d.zip
Migrate from deprecated React.Component.refs
-rw-r--r--app/components/Switch.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/components/Switch.js b/app/components/Switch.js
index 0862d95640..0b50a7af74 100644
--- a/app/components/Switch.js
+++ b/app/components/Switch.js
@@ -16,6 +16,9 @@ export default class Switch extends Component {
isOn: false
}
+ ref: ?HTMLInputElement;
+ onRef = (e: HTMLInputElement) => this.ref = e;
+
state = {
isTracking: false,
ignoreChange: false,
@@ -37,6 +40,7 @@ export default class Switch extends Component {
return;
}
+ const inputElement = this.ref;
const { x: x0 } = this.state.initialPos;
const { pageX: x, pageY: y } = e;
const dx = Math.abs(x0 - x);
@@ -59,7 +63,11 @@ export default class Switch extends Component {
initialPos: { x, y },
ignoreChange: true
});
- this.refs.input.checked = nextOn;
+
+ if(inputElement) {
+ inputElement.checked = nextOn;
+ }
+
this.notify(nextOn);
}
}
@@ -116,7 +124,7 @@ export default class Switch extends Component {
render(): React.Element<*> {
return (
- <input type="checkbox" ref="input" className="switch" checked={ this.props.isOn }
+ <input type="checkbox" ref={ this.onRef } className="switch" checked={ this.props.isOn }
onMouseDown={ this.handleMouseDown }
onChange={ this.handleChange } />
);