Layout improvements, some additions
This commit is contained in:
25
front/hooks/ErrorHandler.ts
Normal file
25
front/hooks/ErrorHandler.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { useState } from "react";
|
||||
|
||||
type ErrorT = {
|
||||
message?: string;
|
||||
has: boolean;
|
||||
};
|
||||
|
||||
const useErrorHandler = <T extends Function>(
|
||||
dispatcher: T
|
||||
): {
|
||||
error: ErrorT;
|
||||
gotError: (err: Error) => void;
|
||||
resetError: () => void;
|
||||
} => {
|
||||
const [error, setError] = useState<ErrorT>({ has: false });
|
||||
|
||||
const gotError = (err: Error) =>
|
||||
setError({ has: true, message: dispatcher(err) });
|
||||
|
||||
const resetError = () => setError({ has: false });
|
||||
|
||||
return { error, gotError, resetError };
|
||||
};
|
||||
|
||||
export default useErrorHandler;
|
Reference in New Issue
Block a user