-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
55 lines (44 loc) · 1.25 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import './App.css';
import { useState, useEffect } from 'react';
import Editor from './Editor';
import useLocalStorage from './hooks/useLocalStorage';
function App() {
const [html, setHtml] = useLocalStorage('html', '')
const [css, setCss] = useLocalStorage('css', '')
const [js, setJs] = useLocalStorage('js', '')
const [srcDoc, setSrcDoc] = useState('')
useEffect(() => {
const timeout = setTimeout(() =>{
setSrcDoc(
`
<html>
<body>${html}</body>
<style>${css}</style>
<script>${js}</script>
</html>
`
);
}, 250)
return ()=> clearTimeout(timeout)
}, [html, css, js])
return (
<>
<div className="pane top-pane">
<Editor language="xml" displayName="HTML" value={html} onChange={setHtml}/>
<Editor language="css" displayName="CSS" value={css} onChange={setCss}/>
<Editor language="javascript" displayName="JS" value={js} onChange={setJs}/>
</div>
<div className="pane">
<iframe
srcDoc={srcDoc}
titile="output"
sandbox="allow-scripts"
frameBorder="0"
width="100%"
height="100%"
/>
</div>
</>
);
}
export default App;