Skip to content

Instantly share code, notes, and snippets.

@LukeMwila
Created May 8, 2019 18:29
Show Gist options
  • Save LukeMwila/7f470b4583627aecbd807d69b74b111d to your computer and use it in GitHub Desktop.
Save LukeMwila/7f470b4583627aecbd807d69b74b111d to your computer and use it in GitHub Desktop.
Custom hook
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