-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
useOf.ts
23 lines (21 loc) · 810 Bytes
/
useOf.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type {
DocsContextProps,
ResolvedModuleExportType,
ResolvedModuleExportFromType,
} from '@storybook/types';
import { useContext } from 'react';
import { DocsContext } from './DocsContext';
export type Of = Parameters<DocsContextProps['resolveOf']>[0];
/**
* A hook to resolve the `of` prop passed to a block.
* will return the resolved module
* if the resolved module is a meta it will include a preparedMeta property similar to a preparedStory
* if the resolved module is a component it will include the project annotations
*/
export const useOf = <TType extends ResolvedModuleExportType>(
moduleExportOrType: Of,
validTypes?: TType[]
): ResolvedModuleExportFromType<TType> => {
const context = useContext(DocsContext);
return context.resolveOf(moduleExportOrType, validTypes);
};