Last active
December 30, 2022 01:49
-
-
Save muhrizqiardi/d516c294c54359c0f96649168b4c277e to your computer and use it in GitHub Desktop.
React Error Hook
This file contains 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 { 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