UNPKG

@bytedance/mona

Version:

Merchant app's developing and building tools

24 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAppEvent = useAppEvent; exports.usePageEvent = usePageEvent; const react_1 = require("react"); const context_1 = require("./context"); ; // for app function useAppEvent(eventName, callback) { const appLifecycle = (0, react_1.useContext)(context_1.AppLifecycleGlobalContext); (0, react_1.useLayoutEffect)(() => { let clear = appLifecycle === null || appLifecycle === void 0 ? void 0 : appLifecycle.registerLifecycle(eventName, callback); return () => clear === null || clear === void 0 ? void 0 : clear(); }, [callback, eventName, appLifecycle]); } // for page function usePageEvent(eventName, callback) { const pageLifecycleContext = (0, react_1.useContext)(context_1.PageLifecycleGlobalContext); (0, react_1.useLayoutEffect)(() => { let clear = pageLifecycleContext === null || pageLifecycleContext === void 0 ? void 0 : pageLifecycleContext.registerLifecycle(eventName, callback); return () => clear === null || clear === void 0 ? void 0 : clear(); }, [callback, eventName, pageLifecycleContext]); } //# sourceMappingURL=hooks.js.map