I have created a Notification Toast service which seems to be working except for some typescript errors surrounding the ToastContext.
Calling the toast on any page I import my useToast() hook which connects to the contextProvider. The typescript error occurs with the toast(...) function. The error I receive is
Error
This expression is not callable. Type '{}' has no call signatures.
Toast Hook
<button
onClick={() => {
return toast({
title: "I am toasty"
});
}}
>Toast Me</button>
Context & useContext hook
export const ToastContext = createContext({});
export function useToast() {
return useContext(ToastContext);
}
Here is a codesandbox to the current code https://codesandbox.io/s/dazzling-spence-clehl.
I have tried typing my createContext with
interface ContextType {
toasts: []
toast: () => void
}
export const ToastContext = createContext<ContextType | {}>({});