File tree Expand file tree Collapse file tree 3 files changed +7
-1
lines changed
src/components/ComponentsProvider Expand file tree Collapse file tree 3 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -3,5 +3,6 @@ import { ComponentsContextInterface } from './interface';
3
3
4
4
export const ComponentsContext = React . createContext < ComponentsContextInterface > ( {
5
5
addComponent : ( ) => { } ,
6
+ hasComponent : ( ) => false ,
6
7
getComponent : ( ) => null ,
7
8
} ) ;
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ export const ComponentsProvider: React.FC<ComponentsProviderProps> = (props) =>
20
20
componentsRef . current [ code ] = val ;
21
21
}
22
22
23
+ function hasComponent ( code : string ) {
24
+ return componentsRef . current . hasOwnProperty ( code ) ;
25
+ }
26
+
23
27
function getComponent ( code : string , callback : GetComponentCallback = ( ) => { } ) {
24
28
const comp = componentsRef . current [ code ] ;
25
29
@@ -71,7 +75,7 @@ export const ComponentsProvider: React.FC<ComponentsProviderProps> = (props) =>
71
75
}
72
76
73
77
return (
74
- < ComponentsContext . Provider value = { { addComponent, getComponent } } >
78
+ < ComponentsContext . Provider value = { { addComponent, hasComponent , getComponent } } >
75
79
{ children }
76
80
</ ComponentsContext . Provider >
77
81
) ;
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export interface GetComponentCallback {
38
38
39
39
export interface ComponentsContextInterface {
40
40
addComponent : ( code : string , value : ComponentInterface ) => void ;
41
+ hasComponent : ( code : string ) => boolean ;
41
42
getComponent : (
42
43
code : string ,
43
44
callback ?: GetComponentCallback ,
You can’t perform that action at this time.
0 commit comments