"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _default = function _default(relEntryFile) { return relEntryFile ? "import { useState, useEffect, useCallback } from 'react';\nimport { Models } from '../../plugin-model/useModel';\nimport * as app from '../../../app';\n\nexport type InitialState = Models<'@@initialState'>;\nasync function getInitialState() {\n return await app.getInitialState();\n}\n\ntype ThenArg = T extends Promise ? U : T\n\nconst initState = {\n initialState: undefined as ThenArg> | undefined,\n loading: true,\n error: undefined as Error | undefined,\n}\n\nexport default () => {\n const [ state, setState ] = useState(initState);\n\n const refresh = useCallback(async() => {\n setState(s => ({ ...s, loading: true, error: undefined }))\n try {\n const asyncFunc = () => new Promise>(res => res(getInitialState()));\n const ret = await asyncFunc();\n setState(s => ({ ...s, initialState: ret, loading: false }));\n } catch(e) {\n setState(s => ({ ...s, error: e, loading: false }));\n }\n }, []);\n\n const setInitialState = useCallback((initialState: ThenArg> | undefined) => {\n setState(s => ({ ...s, initialState, loading: false }))\n }, []);\n\n useEffect(()=>{\n refresh();\n }, []);\n\n return {\n ...state,\n refresh,\n setInitialState,\n }\n}\n" : 'export default () => ({ loading: false, refresh: () => {} })'; }; exports.default = _default;