Skip to content

创建一个应用

使用 Vite

bash
pnpm create vite@7
详细说明
  • react:v19
  • react-dom: v19
  • @vitejs/plugin-react: v5
  • typescript: v5
  • vite: v7

使用 CDN

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <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>
  </head>
  <body>
    <div id="app"></div>

    <script type="text/babel">
      const { useState, useEffect } = React

      const App = () => {
        const [count, setCount] = useState(0)

        useEffect(() => {
          document.title = `${count} times`
        }, [count])

        const handleClick = () => setCount(count + 1)

        return <button onClick={handleClick}>点击了 {count} 次</button>
      }
      const root = ReactDOM.createRoot(document.getElementById('app'))
      root.render(<App />)
    </script>
  </body>
</html>

基于 MIT 许可发布