diff --git a/COMMIT.md b/COMMIT.md index ad689921..602a3e53 100644 --- a/COMMIT.md +++ b/COMMIT.md @@ -4,7 +4,9 @@ Emoji reference of Commitizen scopes for this repo: 📦 BlueRainModule 🎁 ComponentRegistry 🎣 HookRegistry +🎣 BlueRainHook Component 🗿 Icons +🍱 JSON Schema 🔌 PluginRegistry 📖 README 📕 Storybook diff --git a/src/components/BlueRainHook/BlueRainHook.tsx b/src/components/BlueRainHook/BlueRainHook.tsx new file mode 100644 index 00000000..c0a87070 --- /dev/null +++ b/src/components/BlueRainHook/BlueRainHook.tsx @@ -0,0 +1,45 @@ +import { BlueRain } from '../../BlueRain'; +import { BlueRainConsumer } from '../../Context'; +import Loadable from 'react-loadable'; +import React from 'react'; + +// const example = () => ( +// +// {(value) => console.log(value)} +// +// ); + +export interface BlueRainHookProperties { + hook: string; + value: T; + args?: { [key: string]: any }; + children: ((value: any) => React.ReactNode); +} + +export class BlueRainHook extends React.PureComponent { + + public static defaultProps = { + args: {} + }; + + render() { + + const { hook, value, args, children } = this.props; + + return ( + { + + const AsyncBlueRainHook = Loadable({ + loader: () => BR.Hooks.run(hook, value, args), + loading: () => Loading, + render(loadedValue: any) { + return children(loadedValue); + } + }); + + return ; + + }} /> + ); + } +} diff --git a/src/components/BlueRainHook/index.ts b/src/components/BlueRainHook/index.ts new file mode 100644 index 00000000..0153e9aa --- /dev/null +++ b/src/components/BlueRainHook/index.ts @@ -0,0 +1 @@ +export * from './BlueRainHook';