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
/** @jsxImportSource https://esm.sh/react **/
// Make sure to only import from esm.sh (npm: specifier are not supported in the browser)
import ReactDOM from "https://esm.sh/react-dom";
import React, { useState, useEffect } from "https://esm.sh/react@18.0.0";
function TestComponent() {
return <div>Test Component</div>;
}
export function App() {
const [isReady, setIsReady] = useState(false);
useEffect(() => {
setIsReady(true);
}, []);
if (!isReady) {
return <div>Loading...</div>;
}
return (
<>
<div style={{ position: "fixed", inset: 0 }}>
<TestComponent />
</div>
</>
);
}
// The app will be rendered inside the root div
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 5, 2024