前提・実現したいこと
現在Reactを勉強しています。
結論から言うと、Reactでlocalhost:3000を表示したときの呼び出されるファイルの流れが知りたいです。
index.htmlが呼び出されそうですが、そうではなく、index.jsが呼び出されるのでしょうか。
Reactをはじめる#index を詳しくみる
上記でもindex.jsがエントリーポイントと書いてありますもんね。
index.htmlはテンプレートファイルのようなもので、index.jsから呼び出されているのでしょうか。
通常のHTMLではindex.htmlからindex.jsを呼び出す記述を書いて、index.jsの処理が実行されるので、いまいちしっくりしていません。逆といいますか、index.jsがエントリポイントで、そこからindex.htmlが呼び出されているのでしょうか。
だとしたらimport文にindex.htmlが書いていてほしいような気がしますが、それもありません。
▼index.js
js
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import './index.css'; 4import App from './App'; 5import reportWebVitals from './reportWebVitals'; 6 7ReactDOM.render( 8 <React.StrictMode> 9 <App /> 10 </React.StrictMode>, 11 document.getElementById('root') 12); 13 14// If you want to start measuring performance in your app, pass a function 15// to log results (for example: reportWebVitals(console.log)) 16// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17reportWebVitals(); 18
私の認識・予想は以下です。
・index.html,index.js,App.jsが主要な3ファイル
・index.jsが呼び出され、その中のdocument.getElementById('root')
で、index.htmlのid属性rootにindex.js内で構成した内容をレンダリング(反映)している?(←ここが知りたい。index.jsからindex.htmlを呼び出している?流れや仕組みが知りたい)
・index.jsではApp.jsの内容をインポートして(import App from './App';
)、<App />
の部分で反映している
・基本index.htmlは修正しない。index.jsもだろうか。基本App.jsを編集したり、新たにComponentを作ってApp.jsから呼び出す。
少し記事を読んでもしっくり来ていないし、あくまで予想になっているので、有権者の方にお聞きさせていただきたいです。
試したこと
・「react index.js どうやって読み込まれてる?」などで検索
・「react 仕組み」などで検索
・表示された記事を参照
回答1件
あなたの回答
tips
プレビュー