From e51a2042dfaca9775ec2e6bde162e11f7ef37d17 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Fri, 29 Dec 2017 10:20:27 -0600 Subject: [PATCH] hotfix(global error): only setTimeout when theres an error --- app/components/GlobalError/GlobalError.js | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/components/GlobalError/GlobalError.js b/app/components/GlobalError/GlobalError.js index 8707296b..01458cc2 100644 --- a/app/components/GlobalError/GlobalError.js +++ b/app/components/GlobalError/GlobalError.js @@ -3,22 +3,29 @@ import PropTypes from 'prop-types' import { MdClose } from 'react-icons/lib/md' import styles from './GlobalError.scss' -const GlobalError = ({ error, clearError }) => { - setTimeout(clearError, 10000) +class GlobalError extends React.Component { + componentDidUpdate(prevProps) { + if (!prevProps.error && this.props.error) { + setTimeout(this.props.clearError, 10000) + } + } - return ( -
-
-
- + render() { + const { error, clearError } = this.props + + return ( +
+
+
+ +
+

{error}

-

{error}

-
- ) + ) + } } - GlobalError.propTypes = { error: PropTypes.string, clearError: PropTypes.func.isRequired