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

Function useLazyModal

packages/shared/src/hooks/useLazyModal.ts:15–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13let scrollPosition = 0;
14
15export function useLazyModal<
16 K extends keyof ModalsType,
17 T extends LazyModalType<K> = LazyModalType<K>,
18>(): UseLazyModal<K, T> {
19 const client = useQueryClient();
20 const { data: modal } = useQuery({
21 queryKey: MODAL_KEY,
22 queryFn: () => client.getQueryData<T>(MODAL_KEY),
23 enabled: false,
24 });
25 const openModal = useCallback(
26 (data: T) => {
27 scrollPosition = window.scrollY;
28
29 client.setQueryData(MODAL_KEY, data);
30 },
31 [client],
32 );
33 const closeModal = useCallback(() => {
34 window.scrollTo(0, scrollPosition);
35 scrollPosition = 0;
36
37 client.setQueryData(MODAL_KEY, null);
38 }, [client]);
39
40 return useMemo(
41 () => ({
42 openModal,
43 closeModal,
44 modal: modal as T,
45 }),
46 [openModal, closeModal, modal],
47 );
48}

Callers 15

MarkdownFunction · 0.90
CustomFeedOptionsMenuFunction · 0.90
ShareBarFunction · 0.90
PlusInfoFunction · 0.90
PlusMarketingModalFunction · 0.90
BookmarkButtonFunction · 0.90
BookmarkButtonFunction · 0.90
PersonalizedDigestFunction · 0.90
InAppNotificationsTabFunction · 0.90
LiveRoomTileActionsFunction · 0.90
AwardButtonFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected