1
- import React , { useEffect , useRef , useContext } from 'react' ;
1
+ import React , { useState , useEffect , useRef , useContext } from 'react' ;
2
2
import { BrowserRouter as Router , Switch , Route , Link } from "react-router-dom" ;
3
3
import Box from '@material-ui/core/Box' ;
4
4
import cssRefresher from '../../helperFunctions/cssRefresh' ;
@@ -9,14 +9,28 @@ import { Component } from '../../interfaces/Interfaces';
9
9
// 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
10
// real react components that utilize hot module reloading to depict the user's prototype application.
11
11
const DemoRender = ( ) : JSX . Element => {
12
-
13
12
const [ state , ] = useContext ( StateContext ) ;
13
+ console . log ( 'state line 14' , state ) ;
14
14
let currentComponent = state . components . find (
15
15
( elem : Component ) => elem . id === state . canvasFocus . componentId
16
16
) ;
17
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
+
18
32
console . log ( 'state in DemoRender' , state ) ;
19
- console . log ( 'currentComponent' , currentComponent ) ;
33
+ console . log ( 'currentComponent.code ' , currentComponent . code ) ;
20
34
21
35
// Create React ref to inject transpiled code in inframe
22
36
const iframe = useRef < any > ( ) ;
@@ -26,13 +40,15 @@ const DemoRender = (): JSX.Element => {
26
40
border : '2px Solid grey' ,
27
41
} ;
28
42
29
- // let code = useSelector((state) => state.code);
30
- let code = `<div style="color: red">Will this work?</div><div>second</div>`
31
- const html = `<html>
32
- <head>
33
- </head>
43
+ let code = useSelector ( ( state ) => state . code ) ;
44
+
45
+ const html = `
46
+ <html>
47
+ <head>
48
+ </head>
34
49
<body>
35
50
<div id="app">
51
+ <h1>HELLO WORLD</h1>
36
52
</div>
37
53
<script>
38
54
window.addEventListener('message', (event) => {
@@ -77,12 +93,14 @@ const DemoRender = (): JSX.Element => {
77
93
return componentsToRender ;
78
94
} ;
79
95
96
+
80
97
useEffect ( ( ) => {
81
98
cssRefresher ( ) ;
82
99
} , [ ] )
83
100
84
101
useEffect ( ( ) => {
85
- iframe . current . contentWindow . postMessage ( code , '*' ) ;
102
+ console . log ( 'code' , code ) ;
103
+ iframe . current . contentWindow . postMessage ( code , '*' ) ;
86
104
} , [ code ] )
87
105
88
106
return (
0 commit comments