0
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?

Vite+React基本メモ

Posted at

構築直後

今回は、Viteを使用して環境構築をした。
フレームワークは、React
言語は、JavaScriptを選択している。

index.html
スクリーンショット 2025-02-03 120051.jpg

index.htmlを見てみると、srcフォルダのmain.jsxを表示していることが分かる。

main.jsx
スクリーンショット 2025-02-03 120323.png

main.jsxでは、<App />を呼び出して使用していることが分かる。
上部のimportを確認すると、

import App from './App.jsx'

と記述がある。
つまり、Appの中身は、App.jsxに記載されているということだ。

App.jsx
スクリーンショット 2025-02-03 120911.png
Appというファンクションを使用した際に、returnの中を返す。

export default App

で、デフォルトでAppを表示する。

関数の使用

先ほど見ていったように、関数を定義し、呼び出して使用することができる。
始めてReactを使用した際に、私が抜けてしまった点も踏まえて基本的な関数の使用についてメモしておく。

まずは、関数を定義。
returnとexport default 関数名
を忘れずに。
スクリーンショット 2025-02-03 121810.png

次に、使用する側(今回はmain.jsx)で、インポートして使用する。
また、今回は、propsで変数を使用したため、呼び出し内で変数を定義している。
スクリーンショット 2025-02-03 121913.png

自分がニワトリ頭すぎるので、備忘録として。順次更新予定。
こんな基礎的なこと、と思うけれど、ふとした瞬間に抜けてしまうんですよね。
これからReact勉強頑張ります。

0
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
0
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?