Skip to content

Commit

Permalink
chore: Update React components and add like functionality to pure-rea…
Browse files Browse the repository at this point in the history
…ct.html
  • Loading branch information
arloor committed Oct 23, 2024
1 parent 92f0cfd commit 4302a8c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>

<body>
<div id="app"></div>

<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 src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

<script type="text/jsx">
const app = document.getElementById("app")

function Header({ title }) {
return <h1>{title ? title : "Default title"}</h1>
}

function HomePage() {
const names = ["pure-react"]


return (
<div>
<Header title="Develop. Preview. Ship." />
<ul>
{names.map((name) => {
let href = `learn/${name}.html`;
return (<li key={name}><a href={href}>{name}</a></li>);
})}
</ul>
</div>
)
}

const root = ReactDOM.createRoot(app);
root.render(<HomePage />);
</script>
</body>

</html>
45 changes: 45 additions & 0 deletions learn/pure-react.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html>

<body>
<div id="app"></div>

<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 src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

<script type="text/jsx">
const app = document.getElementById("app")

function Header({ title }) {
return <h1>{title ? title : "Default title"}</h1>
}

function HomePage() {
const names = ["Ada Lovelace", "Grace Hopper", "Margaret Hamilton"]

const [likes, setLikes] = React.useState(0)

function handleClick() {
setLikes(likes + 1)
}

return (
<div>
<Header title="Develop. Preview. Ship." />
<ul>
{names.map((name) => (
<li key={name}>{name}</li>
))}
</ul>

<button onClick={handleClick}>Like ({likes})</button>
</div>
)
}

const root = ReactDOM.createRoot(app);
root.render(<HomePage />);
</script>
</body>

</html>

0 comments on commit 4302a8c

Please sign in to comment.