startit/react_test/tutorial/index.html

47 lines
1.3 KiB
HTML

<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 domNode = document.getElementById('app');
function createTitle(title) {
if (title) {
return title;
} else {
return 'Default title';
}
}
function Header({ title }) {
return <h1>{title ? title : 'Default Title'}</h1>;
}
function HomePage() {
const names = ['Ada Lovlace', 'Grace Hopper', 'Margaret Hamilton'];
function handleClick(){
console.log("increment like count")
}
return( <div>
<Header title="Develop. Preview. Ship." />
<ul>
{names.map((name) => (
<li key={name}>{name}</li>
))}
</ul>
<button onClick={handleClick}>Like</button>
</div>
);
}
const root = ReactDOM.createRoot(domNode);
root.render(<HomePage />);
</script>
</body>
</html>