Add state
This commit is contained in:
parent
85924128db
commit
09c51715a2
32
index.html
32
index.html
@ -6,17 +6,35 @@
|
|||||||
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
||||||
<script type="text/jsx">
|
<script type="text/jsx">
|
||||||
const app = document.getElementById('app');
|
const app = document.getElementById('app');
|
||||||
|
const blurb_data = {
|
||||||
|
title: "Fart Man Comes To Town!",
|
||||||
|
blurb: "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 believe the imminent winds of change will revitalize the towns central business district."
|
||||||
|
};
|
||||||
|
|
||||||
function Header() {
|
function Blurb({ title, blurb }) {
|
||||||
return(<h1>Fart man approaches...</h1>);
|
return (<div>
|
||||||
|
<h1>{ title }</h1>
|
||||||
|
<p>{ blurb }</p>
|
||||||
|
<a href="#">Read more...</a>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
function HomePage() {
|
||||||
|
const [blurbs, setBlurbs] = React.useState([ blurb_data ])
|
||||||
|
function addBlurb() {
|
||||||
|
setBlurbs(blurbs.concat([blurb_data]));
|
||||||
|
}
|
||||||
|
return (<>
|
||||||
|
{blurbs.map((blurb, i) => (
|
||||||
|
<Blurb key={i} {...blurb} />
|
||||||
|
))}
|
||||||
|
<br />
|
||||||
|
<button onClick={addBlurb}>Load More</button>
|
||||||
|
</>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(app);
|
const root = ReactDOM.createRoot(app);
|
||||||
root.render(<>
|
root.render(<HomePage />);
|
||||||
<Header />
|
|
||||||
<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>
|
|
||||||
<a href="#">Read more...</a>
|
|
||||||
</>);
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user