MCPcopy Create free account
hub / github.com/dailydotdev/apps / useToastNotification

Function useToastNotification

packages/shared/src/hooks/useToastNotification.ts:57–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55>;
56
57export const useToastNotification = (): UseToastNotification => {
58 const client = useQueryClient();
59 const { data: toast } = useQuery<ToastNotification | null>({
60 queryKey: TOAST_NOTIF_KEY,
61 queryFn: () =>
62 client.getQueryData<ToastNotification | null>(TOAST_NOTIF_KEY) ?? null,
63 initialData: () =>
64 client.getQueryData<ToastNotification | null>(TOAST_NOTIF_KEY) ?? null,
65 });
66 const setToastNotification = (data: ToastNotification) =>
67 client.setQueryData(TOAST_NOTIF_KEY, data);
68
69 const displayToast = (
70 message: ReactNode,
71 { timer = 5000, ...props }: NotifyOptionalProps = {},
72 ) => setToastNotification({ message, timer, ...props });
73
74 return useMemo(
75 () => ({
76 displayToast,
77 subject: toast?.subject,
78 dismissToast: () => {
79 if (!toast) {
80 return;
81 }
82
83 setToastNotification({ ...toast, timer: 0 });
84 },
85 }),
86 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
87 // eslint-disable-next-line react-hooks/exhaustive-deps
88 [toast],
89 );
90};

Callers 15

PlusIOSFunction · 0.90
UploadButtonFunction · 0.90
ComponentWithToastFunction · 0.90
LiveRoomInnerFunction · 0.90
LiveRoomControlsFunction · 0.90
PreferenceOptionsFormFunction · 0.90
OpportunityEditInfoModalFunction · 0.90

Calls 1

setToastNotificationFunction · 0.85

Tested by 1

ComponentWithToastFunction · 0.72