@@ -6,6 +6,8 @@ import { useSelector } from 'react-redux';
6
6
import StateContext from '../../context/context' ;
7
7
import { Component } from '../../interfaces/Interfaces' ;
8
8
9
+ import ReactDOMServer from 'react-dom/server' ;
10
+
9
11
// DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
10
12
// real react components that utilize hot module reloading to depict the user's prototype application.
11
13
const DemoRender = ( ) : JSX . Element => {
@@ -14,24 +16,8 @@ const DemoRender = (): JSX.Element => {
14
16
let currentComponent = state . components . find (
15
17
( elem : Component ) => elem . id === state . canvasFocus . componentId
16
18
) ;
17
-
18
- // const iframe = useRef<any>(); --> we already have this on line 36
19
- // const [components, setComponents] = useState([]);
20
- // const [state, dispatch] = useContext(StateContext);
21
- // const [codeRender, setCodeRender] = useState('') --> not sure about what this does
22
- // const demoContainerStyle = {
23
- // width: '100%',
24
- // backgroundColor: '#FBFBFB',
25
- // border: '2px Solid grey',
26
- // };
27
-
28
-
29
-
30
-
31
-
32
- console . log ( 'state in DemoRender' , state ) ;
33
- console . log ( 'currentComponent.code' , currentComponent . code ) ;
34
19
20
+ console . log ( 'currentComponent.code' , currentComponent . code ) ;
35
21
// Create React ref to inject transpiled code in inframe
36
22
const iframe = useRef < any > ( ) ;
37
23
const demoContainerStyle = {
@@ -40,20 +26,20 @@ const DemoRender = (): JSX.Element => {
40
26
border : '2px Solid grey' ,
41
27
} ;
42
28
43
- let code = useSelector ( ( state ) => state . code ) ;
29
+ // let code = useSelector((state) => state.code);
44
30
45
31
const html = `
46
32
<html>
47
33
<head>
48
34
</head>
49
35
<body>
50
36
<div id="app">
51
- <h1>HELLO WORLD</h1>
37
+
52
38
</div>
53
39
<script>
54
40
window.addEventListener('message', (event) => {
55
41
try {
56
- eval( event.data) ;
42
+ app.innerHTML = event.data;
57
43
} catch (err) {
58
44
const app = document.querySelector('#app');
59
45
app.innerHTML = '<div style="color: red;"><h4>Syntax Error</h4>' + err + '</div>';
@@ -92,7 +78,9 @@ const DemoRender = (): JSX.Element => {
92
78
}
93
79
return componentsToRender ;
94
80
} ;
95
-
81
+
82
+ let code = '' ;
83
+ componentBuilder ( state . components [ 0 ] . children ) . forEach ( element => code += ReactDOMServer . renderToString ( element ) ) ;
96
84
97
85
useEffect ( ( ) => {
98
86
cssRefresher ( ) ;
0 commit comments