You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project I'm working on where some toasts get dispatched while a modal, with an outside observer, is open. The problem I ran into was clicking a toast to dismiss it, would close the modal (behavior of the outside observer -- intended).
To alleviate this, I add the following toastOption onClick: (e) => e.stopPropogation()
Since I want all my calls to toast to have that onClick, I had to create a wrapper like so:
import { ReactText } from 'react';
import { toast as dispatchToast, ToastOptions, TypeOptions } from 'react-toastify';
export const toast = (type: TypeOptions): ((content: string, options?: ToastOptions) => ReactText) => {
const defaultOptions: ToastOptions = {
onClick: (e) => e.stopPropagation()
};
let dispatch: typeof dispatchToast | typeof dispatchToast[Exclude<TypeOptions, 'default'>];
// default is not an argument to toast, so we handle that case this way
if (type === 'default') dispatch = dispatchToast;
else dispatch = dispatchToast[type];
return (content: string, options?: ToastOptions) => dispatch(content, { ...defaultOptions, ...options });
};
It would be much easier if we can just configure default toastOptions somewhere rather than going through this approach.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a project I'm working on where some toasts get dispatched while a modal, with an outside observer, is open. The problem I ran into was clicking a toast to dismiss it, would close the modal (behavior of the outside observer -- intended).
To alleviate this, I add the following toastOption
onClick: (e) => e.stopPropogation()
Since I want all my calls to toast to have that
onClick
, I had to create a wrapper like so:It would be much easier if we can just configure default toastOptions somewhere rather than going through this approach.
Beta Was this translation helpful? Give feedback.
All reactions