Skip to main content

context-composer

React.Context 生成工具,快速绑定 ProviderReact.useContext 数据使用,同时提供多 React.Context 合并能力

安装

npm install @jelper/context-composer

样例

全局context使用

glabalType: light

多context合并使用

glabalType: light

glabalType1: light1

buildHooks使用

glabalType: light

API

createCtxComposer<Props, T>

创建React.createContext, 方便 Provider 引入和 useContext 使用

参数
  • useCfgHook: (props: Props) => T
返回值
  • result<Object>

    • forwardComposer: (Com: FC<Props>) => FC<Props>

    • useComposerCtx: T

    • buildHooks: <F extends (...arg: any) => any>(cb: (value: T) => F) => (...p: Parameters<F>) => ReturnType<F>;

mergeComposer

参数
  • list: Array<(Com: FC<Props>) => FC<Props>>
返回值
  • result: (Com: FC<Props>) => FC<Props>