UNPKG

@nokecy/umi-plugin-erp-common

Version:

erp-common

40 lines (30 loc) 1.16 kB
import { utils } from 'umi'; import { join } from 'path'; export default function(util: typeof utils) { return `\ import React, { useMemo } from 'react'; import { useModel } from '../core/umiExports'; import erpCommonFactory from '../../erpCommon'; import ErpCommonContext, { ErpCommonInstance } from './context'; interface Props { children: React.ReactNode; } const ErpCommonProvider: React.FC<Props> = props => { if (typeof useModel !== 'function') { throw new Error('[plugin-erpCommon]: useModel is not a function, @umijs/plugin-initial-state is needed.') } const { children } = props; const { initialState } = useModel('@@initialState'); const erpCommon: ErpCommonInstance = useMemo(() => erpCommonFactory(initialState as any), [initialState]); if (process.env.NODE_ENV === 'development' && (erpCommon === undefined || erpCommon === null)) { console.warn('[plugin-erpCommon]: the erpCommon instance created by erpCommon.ts(js) is nullish, maybe you need check it.'); } return React.createElement( ErpCommonContext.Provider, { value: erpCommon }, children, ); }; export default ErpCommonProvider; `; }