File tree 2 files changed +10
-13
lines changed
2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -41,15 +41,10 @@ class Ctx implements IStringToReactApi {
41
41
}
42
42
}
43
43
}
44
- getModule ( code : string ) : Promise < any > {
44
+ getModule ( code : string , babelOptions : TransformOptions ) : Promise < any > {
45
+ this . _checkBabelOptions ( babelOptions ) ;
45
46
code = `import React from "react";\nexport default ${ code } ` ;
46
- const op : TransformOptions = {
47
- presets : [ 'react' , [ 'env' , { modules : false } ] ] ,
48
- filename : 'counter.js' ,
49
- sourceMaps : 'inline' ,
50
- sourceType : 'module' ,
51
- } ;
52
- const resultObj = this . _getBabel ( ) . transform ( code , op ) ;
47
+ const resultObj = this . _getBabel ( ) . transform ( code , babelOptions ) ;
53
48
// 1. Define your module code as a string
54
49
code = resultObj . code || '' ;
55
50
code = code
Original file line number Diff line number Diff line change @@ -8,24 +8,26 @@ function StringToReactComponent(
8
8
let ref = useRef < any > ( null ) ;
9
9
ref . current = ref . current || getCtx ( react , Babel ) ;
10
10
const api = ref . current as IStringToReactApi ;
11
- // const babelOptions = props.babelOptions || {};
12
- // const GeneratedComponent = api.updateTemplate( props.children || '', babelOptions).getComponent() ;
11
+ const babelOptions = props . babelOptions || { } ;
12
+ const stringCode = props . children || '() => null' ;
13
13
const data = props . data || { } ;
14
+ //const GeneratedComponent = api.updateTemplate(props.children || '', babelOptions).getComponent();
15
+
14
16
//
15
17
const ModuleComponent = useCallback (
16
18
( data : any ) => {
17
- const ref = useRef < { Com : FC < any > } > ( { Com : ( props ) => < p > hhhhhhhhhhhhhhhhhh </ p > } ) ;
19
+ const ref = useRef < { Com : FC < any > } > ( { Com : ( ) => < p > Loading... </ p > } ) ;
18
20
const [ , rerender ] = useState < object > ( { } ) ;
19
21
useEffect ( ( ) => {
20
- api . getModule ( props . children ) . then ( ( Mod : FC ) => {
22
+ api . getModule ( stringCode , babelOptions ) . then ( ( Mod : FC ) => {
21
23
ref . current . Com = Mod ;
22
24
rerender ( { } ) ;
23
25
} ) ;
24
26
} , [ ] ) ;
25
27
const Com = ref . current . Com ;
26
28
return < Com { ...data } /> ;
27
29
} ,
28
- [ props . children ] ,
30
+ [ stringCode , babelOptions ] ,
29
31
) ;
30
32
return < ModuleComponent { ...data } /> ;
31
33
}
You can’t perform that action at this time.
0 commit comments