快速起步一个简单ReactApp
快速起步一个简单ReactApp
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Simple React App</title>
<link rel="icon" href="favicon.svg" />
<!-- app styles -->
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div class="app"></div>
<!-- app logics -->
<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/babel">
(function (window) {
'use strict';
function App() {
const [count, setCount] = React.useState(0);
return (
<div>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
);
}
const root = ReactDOM.createRoot(document.querySelector('.app'));
root.render(<App />);
})(window);
</script>
</body>
</html>