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

Function useToastNotification

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

Source from the content-addressed store, hash-verified

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

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