-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathincorporate.ts
More file actions
29 lines (27 loc) · 851 Bytes
/
incorporate.ts
File metadata and controls
29 lines (27 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {createElement, forwardRef} from 'react';
import {Scope} from './scope';
import {ScopeContext} from './context';
import {default as defaultIncorporator} from './Incorporator'
let Incorporator = defaultIncorporator
export function setIncorporator(f: any) {
Incorporator = f
}
const wrapperComponents: Map<any, React.ComponentType<any>> = new Map();
export function incorporate(type: any) {
if (!wrapperComponents.has(type)) {
wrapperComponents.set(
type,
forwardRef<any, any>((props, ref) =>
createElement(ScopeContext.Consumer, null, (scope: Scope) =>
createElement(Incorporator, {
targetProps: props,
targetRef: ref,
target: type,
scope: scope,
})
)
)
);
}
return wrapperComponents.get(type) as React.ComponentType<any>;
}