From cf84ad3cf594bb0b5057275d0d2c8ad2b03c1a5d Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sun, 7 Jul 2019 17:06:48 +0300 Subject: [PATCH] unwrap if --- frontend/app/components/dropdown/dropdown.tsx | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/frontend/app/components/dropdown/dropdown.tsx b/frontend/app/components/dropdown/dropdown.tsx index 4f6500c1..10e0fe55 100644 --- a/frontend/app/components/dropdown/dropdown.tsx +++ b/frontend/app/components/dropdown/dropdown.tsx @@ -47,24 +47,19 @@ export default class Dropdown extends Component { try { const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; - if (data.clickOutside) { - if (this.state.isActive) { - this.setState({ - isActive: false, - }); - } - } + if (!data.clickOutside) return; + if (!this.state.isActive) return; + this.setState({ + isActive: false, + }); } catch (e) {} } onOutsideClick(e: MouseEvent) { - if (this.rootNode && !this.rootNode.contains(e.target as Node)) { - if (this.state.isActive) { - this.setState({ - isActive: false, - }); - } - } + if (!this.rootNode || this.rootNode.contains(e.target as Node) || !this.state.isActive) return; + this.setState({ + isActive: false, + }); } componentDidMount() {