Skip to content

Instantly share code, notes, and snippets.

@muhrizqiardi
Last active December 30, 2022 01:49
Show Gist options
  • Save muhrizqiardi/d516c294c54359c0f96649168b4c277e to your computer and use it in GitHub Desktop.
Save muhrizqiardi/d516c294c54359c0f96649168b4c277e to your computer and use it in GitHub Desktop.
React Error Hook
import { useState } from "react";
export default function useError(
initialIsError: boolean,
initialErrorMessage: string = ""
) {
const [isError, setIsError] = useState<boolean>(initialIsError);
const [errorMessage, setErrorMessage] = useState<string>(initialErrorMessage);
const setError = (isError: boolean, errorMessage: string = "") => {
setIsError(isError);
setErrorMessage(errorMessage);
};
return {
isError,
errorMessage,
setError,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment