Skip to content

Commit 2c8993a

Browse files
create strintToReact.js file
1 parent 1823d38 commit 2c8993a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/index.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import React, {useRef} from 'react';
21
import Ctx from './ctx.js';
3-
window.React = window.React || React;
4-
function StringToReactComponent(props) {
5-
const ref = useRef(null),
6-
template = props.children;
7-
if (!ref.current) {
8-
ref.current = new Ctx();
9-
}
10-
const GeneratedComponent = ref.current.updateTemplate(template).getComponent();
11-
return <GeneratedComponent {...props} />;
12-
}
13-
export default StringToReactComponent;
2+
import StringToReact from './strintToReact.js';
3+
const getCtx = () => new Ctx();
4+
export default StringToReact.bind(null, {getCtx});

src/strintToReact.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, {useRef} from 'react';
2+
window.React = window.React || React;
3+
function StringToReactComponent({getCtx}, props) {
4+
const ref = useRef(null),
5+
template = props.children;
6+
if (!ref.current) {
7+
ref.current = getCtx();
8+
}
9+
const GeneratedComponent = ref.current.updateTemplate(template).getComponent();
10+
return <GeneratedComponent {...props} />;
11+
}
12+
export default StringToReactComponent;

0 commit comments

Comments
 (0)