1 4
import { useLayoutEffect, useContext } from 'react';
2 4
import { registerLifecycle, Callback, lifeCycleName } from '../lifecycle';
3 4
import PageContext from '../PageContext';
4 4
import AppInstanceContext from '../AppInstanceContext';
5

6
/**
7
 *  Page Hooks
8
 */
9

10 4
export function usePageInstance() {
11 4
  return useContext(PageContext)?.page;
12
}
13

14 4
export { default as useNativeEffect } from './useNativeEffect';
15 4
export { default as useQuery } from './useQuery';
16

17 4
export function usePageEvent(eventName: string, callback: Callback) {
18 4
  const pageInstance = useContext(PageContext)?.page;
19 4
  const lifeCycle = lifeCycleName(eventName);
20 4
  useLayoutEffect(() => {
21 4
    return registerLifecycle(pageInstance, lifeCycle, callback);
22
  });
23
}
24

25
/**
26
 * App Hooks
27
 */
28

29 4
export function useAppEvent(eventName: string, callback: Callback) {
30 4
  const lifeCycle = lifeCycleName(eventName);
31 4
  useLayoutEffect(() => {
32 4
    return registerLifecycle(AppInstanceContext, lifeCycle, callback);
33
  });
34
}

Read our documentation on viewing source code .

Loading