mobx-react#MobXProviderContext TypeScript Examples
The following examples show how to use
mobx-react#MobXProviderContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From electron with MIT License | 6 votes |
/**
* @useInject
* @Mobx 按需注入
*/
export function useInject<P extends keyof StoreTypes>(...storeNames: P[]): UseInjectBackType<P> {
const ProviderStore = React.useContext(MobXProviderContext);
const _Store: Partial<UseInjectBackType<P>> = {};
for (const storeName of storeNames) {
if (!ProviderStore[storeName]) {
throw new Error(`${storeName} is not defined`);
}
_Store[storeName] = ProviderStore[storeName];
}
return _Store as UseInjectBackType<P>;
}
Example #2
Source File: MainStore.ts From jmix-frontend with Apache License 2.0 | 5 votes |
useMainStore = (): MainStore => {
const {mainStore} = React.useContext(MobXProviderContext);
return mainStore;
}
Example #3
Source File: index.tsx From electron with MIT License | 5 votes |
/**
* @注入所有 useInjectAll
*/
export function useInjectAll(): StoreTypes {
return React.useContext(MobXProviderContext) as StoreTypes;
}