taro-hooks
Version:
为 Taro 而设计的 Hooks Library
18 lines • 735 B
JavaScript
import { getCurrentInstance, getCurrentPages } from '@tarojs/taro';
import { useRef } from '@taro-hooks/core';
function usePage(scope) {
var getPageInstance = function getPageInstance() {
if (scope && typeof scope === 'string') {
var _getCurrentInstance$p;
return (_getCurrentInstance$p = getCurrentInstance().page) == null ? void 0 : _getCurrentInstance$p.selectComponent == null ? void 0 : _getCurrentInstance$p.selectComponent(scope);
}
return getCurrentInstance();
};
var pageStack = useRef(getCurrentPages());
var pageInstance = useRef(getPageInstance());
return [pageStack.current.length, {
pageInstance: pageInstance.current,
pageStack: pageStack.current
}];
}
export default usePage;