Created
May 8, 2019 18:29
-
-
Save LukeMwila/7f470b4583627aecbd807d69b74b111d to your computer and use it in GitHub Desktop.
Custom hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
const useErrorHandler = (initialState: string | null) => { | |
const [error, setError] = React.useState(initialState); | |
const showError = (errorMessage: string | null) => { | |
setError(errorMessage); | |
window.setTimeout(() => { | |
setError(null); | |
}, 3000); | |
}; | |
return { error, showError }; | |
}; | |
export default useErrorHandler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment