1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

React入門(1)

1
Last updated at Posted at 2026-05-12

Vite + Reactプロジェクトを作成する

npm create vite@latest

Project name: <プロジェクト名>
Select a framework:
React

Select a variant:
JavaScript


cd <プロジェクト名>

npm install 
npm run dev

ディレクトリ構造
node_modules
public
src
│ App.css
│ App.jsx
│ index.css
│ main.jsx

└───assets
hero.png
react.svg
vite.svg
.gitignore
eslint.config.js
index.html
package-lock.json
package.json
README.md
vite.config.js

viteでの開発サーバーを起動する:

npm run dev

index.html

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="/src/index.css" />
  </head>
  <body>
    <div id="root"></div>
    <script src="/src/App.jsx" type="module" ></script>
  </body>
</html>

src\App.jsx

// react-dom/client から createRoot を読み込む。
import { createRoot } from "react-dom/client"

// Reactアプリの「描画管理オブジェクト」を作成。
// document.getElementById("root")はHTML側の:<div id="root"></div>を取得しています
const root = createRoot(document.getElementById("root"))

// React が: <h1>Hello, React!</h1> をブラウザへ描画します。
root.render(<h1>Hello, React123!</h1>)

src\App.jsx(例2)

import { createRoot } from "react-dom/client"

const root = createRoot(document.getElementById("root"))

root.render(
    <ul>
        <li>Coffee</li>
        <li>Tea</li>
        <li>Milk</li>
    </ul>
)

src\App.jsx(例3)

import { createRoot } from "react-dom/client"

const root = createRoot(document.getElementById("root"))

const reactElement = <h1>Hello from JSX!</h1>

console.log(reactElement)

root.render(
    reactElement
)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?