From cdb2340830b0325dc9a05ba443a1a84c2e835430 Mon Sep 17 00:00:00 2001 From: Jeremia Kimelman Date: Mon, 3 Apr 2017 14:22:51 -0400 Subject: [PATCH] Clear error in between terms and toggling (#649) --- src/components/Glossary.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/Glossary.js b/src/components/Glossary.js index 9d817448..703932ad 100644 --- a/src/components/Glossary.js +++ b/src/components/Glossary.js @@ -27,11 +27,6 @@ class Glossary extends React.Component { this.applyProps(nextProps) } - shouldComponentUpdate(nextProps, nextState) { - if (nextState.error) return true - return false - } - setOpen(isOpen) { if (isOpen) this.glossaryEl.show() else this.glossaryEl.hide() @@ -40,9 +35,10 @@ class Glossary extends React.Component { showTerm(term) { if (!term) return + this.setState({ error: null }) + try { this.glossaryEl.findTerm(term.toLowerCase()) - this.setState({ error: null }) } catch (e) { if (e.message === 'Cannot read property \'elm\' of undefined') { this.setState({ error: `Cannot find "${term}".` }) @@ -53,7 +49,10 @@ class Glossary extends React.Component { applyProps(props) { const { isOpen, term } = props this.setOpen(isOpen) - if (term) this.showTerm(term) + if (term) { + this.setState({ error: null }) + this.showTerm(term) + } } toggleGlossary() {