From 0db12fcd22ceed8e0ed6944ed2125ebef1f8d7a5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 28 Sep 2016 11:05:14 +0100 Subject: [PATCH] Move method & don't wastefullt create elements Put did update with the other react interface methods & don't bother creating the 'current_value' if we throw it away later. --- .../views/directory/NetworkDropdown.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/views/directory/NetworkDropdown.js b/src/components/views/directory/NetworkDropdown.js index 3fcd8bb4..48d5152f 100644 --- a/src/components/views/directory/NetworkDropdown.js +++ b/src/components/views/directory/NetworkDropdown.js @@ -64,6 +64,12 @@ export default class NetworkDropdown extends React.Component { document.removeEventListener('click', this.onDocumentClick, false); } + componentDidUpdate() { + if (this.state.expanded && this.inputTextBox) { + this.inputTextBox.focus(); + } + } + onDocumentClick(ev) { // Close the dropdown if the user clicks anywhere that isn't // within our root element @@ -181,16 +187,8 @@ export default class NetworkDropdown extends React.Component { ; } - componentDidUpdate() { - if (this.state.expanded && this.inputTextBox) { - this.inputTextBox.focus(); - } - } - render() { - let current_value = this._makeMenuOption( - this.state.selectedServer, this.state.selectedNetwork, false - ); + let current_value; let menu; if (this.state.expanded) { @@ -201,6 +199,10 @@ export default class NetworkDropdown extends React.Component { current_value = + } else { + current_value = this._makeMenuOption( + this.state.selectedServer, this.state.selectedNetwork, false + ); } return