Skip to content

Commit 18612de

Browse files
committed
bandaid fix to live rendering
1 parent 4826f30 commit 18612de

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useSelector } from 'react-redux';
66
import StateContext from '../../context/context';
77
import { Component } from '../../interfaces/Interfaces';
88

9+
import ReactDOMServer from 'react-dom/server';
10+
911
// DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
1012
// real react components that utilize hot module reloading to depict the user's prototype application.
1113
const DemoRender = (): JSX.Element => {
@@ -14,24 +16,8 @@ const DemoRender = (): JSX.Element => {
1416
let currentComponent = state.components.find(
1517
(elem: Component) => elem.id === state.canvasFocus.componentId
1618
);
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);
3419

20+
console.log('currentComponent.code', currentComponent.code);
3521
// Create React ref to inject transpiled code in inframe
3622
const iframe = useRef<any>();
3723
const demoContainerStyle = {
@@ -40,20 +26,20 @@ const DemoRender = (): JSX.Element => {
4026
border: '2px Solid grey',
4127
};
4228

43-
let code = useSelector((state) => state.code);
29+
// let code = useSelector((state) => state.code);
4430

4531
const html = `
4632
<html>
4733
<head>
4834
</head>
4935
<body>
5036
<div id="app">
51-
<h1>HELLO WORLD</h1>
37+
5238
</div>
5339
<script>
5440
window.addEventListener('message', (event) => {
5541
try {
56-
eval(event.data);
42+
app.innerHTML = event.data;
5743
} catch (err) {
5844
const app = document.querySelector('#app');
5945
app.innerHTML = '<div style="color: red;"><h4>Syntax Error</h4>' + err + '</div>';
@@ -92,7 +78,9 @@ const DemoRender = (): JSX.Element => {
9278
}
9379
return componentsToRender;
9480
};
95-
81+
82+
let code = '';
83+
componentBuilder(state.components[0].children).forEach(element => code += ReactDOMServer.renderToString(element));
9684

9785
useEffect(() => {
9886
cssRefresher();

0 commit comments

Comments
 (0)