Convert to React JSX
This commit is contained in:
parent
ec9fa157d3
commit
fc16b50fe8
22
index.html
22
index.html
@ -1,19 +1,17 @@
|
|||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="text/javascript">
|
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
|
||||||
|
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
||||||
|
<script type="text/jsx">
|
||||||
const app = document.getElementById('app');
|
const app = document.getElementById('app');
|
||||||
function addElem(element, contents, attrs = {}) {
|
const root = ReactDOM.createRoot(app);
|
||||||
const newElem = document.createElement(element);
|
root.render(<>
|
||||||
newElem.appendChild(document.createTextNode(contents));
|
<h1>Fart man approaches...</h1>
|
||||||
for(const [key, value] of Object.entries(attrs)) {
|
<p>Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town beleave the imminent winds of change will revitalize the towns central business district.</p>
|
||||||
newElem.setAttribute(key, value);
|
<a href="#">Read more...</a>
|
||||||
}
|
</>);
|
||||||
app.appendChild(newElem);
|
|
||||||
}
|
|
||||||
addElem('h1', 'Fart man comes to town!');
|
|
||||||
addElem('p', 'Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town beleave the imminent winds of change will revitalize the towns central business district.');
|
|
||||||
addElem('a', 'Read more...', {href: "#"});
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user