-
Notifications
You must be signed in to change notification settings - Fork 13
React研修資料修正 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React研修資料修正 #73
Conversation
c0cbe13 to
b25b8b9
Compare
|
|
||
| 計算が終わると、リアル DOM は実際に変更されたものだけが更新されます。 | ||
|
|
||
| // "実際に変更されたもの"という文言が少し気になるので |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「算出した、『実際に変更のある部分』のみ、リアル DOM を更新します。」
という表現はどうでしょう。
| // 「コンポーネント内のDOM要素の参照を取得する」は誤解を与えるため避けたいです。React公式Docには、「useRef は、レンダー時には不要な値を参照するための React フックです。」と書かれており、「レンダー時には不要な値を参照する」としたいです。 | ||
| | `useImperativeHandle` | **親** コンポーネント内のDOM要素の参照を取得する | | ||
| | `useDebugValue` | React DevTools でカスタムフックのラベルを表示する | | ||
| // useSyncExternalStoreやuseTransitionなど、React18,19で追加されたHooksを追加するか考えたいです。個人的には、初学者をターゲットとしているので追加しなくても良いかなと思いました。追加しないのであれば、使用頻度が低いuseImperativeHandleとuseDebugValueは削除して良いのかなと思いました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初学者向けに内容を小さくまとめるなら、useCallback、useMemo も同様に外して良いのでは、と思いました。
いずれ自動最適化が働くことを見込んでいます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useCallback, useMemo は実案件での使用頻度が高いので残した方が良いです。
useImperativeHandle や useDebugValue は僕は見たこと無いので削除して良いでしょう。
新しい hooks についてはどっちでも良いと思います。講師次第ですが、口頭で紹介するくらいがちょうどいいのかも?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useCallback, useMemoに関しては同じ理由で自分も残したいです。
react/docs/content/toc/08_state.md
Outdated
| 一方、`state`は、コンポーネント自身が持つ情報で、かつ、書き換えができます。 | ||
| // レンダリング中は書き換えは出来ないですし、書き換えるにしてもmutableな変更は出来ないので、「書き換えができます」とは書きたくないです。 | ||
|
|
||
| 関数型言語では、**純粋関数** と **不純関数** という用語があります。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(今回のPRのスコープ外ですが)「不純関数」ではなく「非純粋関数」ですね。
react/docs/content/toc/08_state.md
Outdated
| // stateは副作用ですが、immutableなので、ある意味「引数のようなもの」と考えることもできます。 | ||
| 公式Docの[純粋性が重要である理由](https://ja.react.dev/reference/rules/components-and-hooks-must-be-pure#why-does-purity-matter) には、「コンポーネントの入力とは props と state とコンテクスト。フックの入力とはその引数。」ともあります。 | ||
| stateを副作用の代表として取り上げたくないです。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state を引数として解釈すれば確かにそうなりますが、「拡大解釈し過ぎでは?」とも思います。
普通に解釈すると、関数の引数である props のみが引数であり、引数が同じであれば結果が同じ(参照透過性)というのが純粋であるための必要条件なので、propsが同じでもstateが変わると返り値が変わるというのは純粋ではないです。
あまりこういったおかしな解釈を広めたくないという思いはありますが、Reactの公式ドキュメントと矛盾するのも良くないですね。純粋云々の記述自体削除してしまったほうが良いと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね
まるまる消してしまってもよいと思いますし、「useStateは副作用か」という見出しを作って、一般的な純粋関数の定義に沿った説明と、公式ドキュメントの説明を両方載せてもよいのかなと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ボリュームの関係で削除することにしました。
react/docs/content/toc/08_state.md
Outdated
| stateは、レンダリング間で値を保持したいもの、かつ、値が書き変わったときに際レンダリングしたい値を保持するもの | ||
| refは、レンダリング間で値を保持したいもの、かつ、値が書き変わったときに際レンダリングしたくない値を保持するもの | ||
|
|
||
| と説明したいです。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
良い説明だと思います。
|
web_frontend定例で、webfrontend_specialistチーム全員をレビュアーにすることにしました。 お忙しいところ恐縮ですが、お時間ある方、レビューをよろしくお願いします。 |
| 基本的には、下記の命名規則を使うことになります。 | ||
|
|
||
| - コンポーネント名は、「**upper camel case**」(e.g. CamelCase) | ||
| // 命名規則ではなくて、守らなければならないReactのルールということを書いておきたいです。[関数を定義する](https://ja.react.dev/learn/your-first-component#step-2-define-the-function) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
規則を解説する章なので、規則であり必ず守る、と明示する立場をとりたいです。
開発案件のコーディングルール、原則的な命名規則、Reactのコンパイル仕様、について、いずれも守らなければ(それぞれ別種の)トラブルになるので、その序列は重要でないという考えです。
例文 :
開発案件はコーディングルールがあらかじめ決められているので、そのルールに従います。
Reactでは下記の命名規則を使います。
- コンポーネント名は、「upper camel case」(e.g. CamelCase) ※落とし穴
...
判断に迷うときは、JS/TSの慣習に従ってください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
はい、補足説明の形で「落とし穴」のリンクを記載する形にしますね。
|
修正が完了したため、再度レビュー依頼をしました。 |
|
|
||
| > const f2 = f0 | ||
| > Object.is(f0, f2) | ||
| true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional) Object.is(NaN, NaN) の例があったほうが === との違いがわかって良いと思いますが、あまり細かいところに踏み込まないつもりであればこのままでも構いません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
面白い内容だと思ったのですが、この章で学んでほしいことではないと思ったので、取り入れないことにしました。
講義で余裕があったら話題に出してみようと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
08_multi_state.svg も透過されているので背景を白にしておいてください。
また、できれば画像の雰囲気を他のものと揃えたいですが、それは optional で良いです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代替案まで書いてくれてありがとうございます。
はい、なくても伝わるので削除して構わないと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
削除しました。
SekiT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
僕からはOKです。
aFumihiroSaito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ご対応頂きありがとうございます。
コメント部分の対応はお任せ致します。
| - 任意の赤色の物の名前, 緑色の物の名前, 青色の物の名前を TSX 内に追加 | ||
| - それぞれが赤色, 青色, 緑色となるようにスタイルを指定 | ||
| - 任意の赤色の物の名前、緑色の物の名前、青色の物の名前を JSX 内に追加 | ||
| - それぞれが赤色、緑色、 青色となるようにスタイルを指定 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - それぞれが赤色、緑色、 青色となるようにスタイルを指定 | |
| - それぞれが赤色、緑色、青色となるようにスタイルを指定 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらで修正しました。
|
|
||
|  | ||
| ここで紹介したもの以外にもさまざまな Hooks が用意されており、 React 19 では全部で17個存在します。 | ||
| なかでも利用頻度の高い API は、 `useState`、`useEffect`、`useReducer`、`useCallback` の4つです。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Optional]
useEffect は極力使わないように、という点を考慮すると、利用頻度の高い対象から外しても良いかもですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他のhooksに比べると使用頻度が高いので、残すことにします。
「極力使わないようにする」というのは、「誤った使い方をしない」という意味で解釈しています。
| # React.memo と useCallback を使ったパフォーマンス改善例 | ||
| レンダー中に重い計算をしている`Button` コンポーネントの再レンダリング回数を最小限にすることを目標とします。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| レンダー中に重い計算をしている`Button` コンポーネントの再レンダリング回数を最小限にすることを目標とします。 | |
| レンダー中に重い計算をしている `Button` コンポーネントの再レンダリング回数を最小限にすることを目標とします。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらで修正しました。
react/exercise/C01/Q1/index.tsx
Outdated
| // * それぞれが赤色, 青色, 緑色となるようにスタイルを指定 | ||
| // * 並びや位置関係、厳密に物の色が正しいかどうかは不問 | ||
| // * 任意の赤色の物の名前、緑色の物の名前、青色の物の名前を JSX 内に追加 | ||
| // * それぞれが赤色、緑色、 青色となるようにスタイルを指定 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // * それぞれが赤色、緑色、 青色となるようにスタイルを指定 | |
| // * それぞれが赤色、緑色、青色となるようにスタイルを指定 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらで修正しました。
|
たくさんのレビューありがとうございます。 マージします。 |

更新内容
React研修資料で改善した方が良さそうなところにコメントをしました。
間違っているコメントやもっとよい改善方法が見つかると思うので、レビューをいただいたあとに清書する予定です。
コメントの修正方針で良いか悪いかだけでも、コメントをお願いします。
--- 2025/03/13 追記 ---
1章〜7章までの範囲外でのコメントが大量に発生してしまったため、こちらは別途 PR を出して対応予定です。
そのため、本 PR では8章〜15章(08_state.md ~ 15_advanced.md)までの範囲を対象とします。
--- 2025/03/23 追記 ---
1章〜7章の修正を別のPRで出すことになっていたのですが、このPRにまとめることになりました。
注意事項
変更内容のまとめ (2025/03/24 追記)
1章 TSXを学ぶ
2章 要素のレンダー
3章 コンポーネントとprops
4章 イベント処理
5章
6章 リストとkey
7章 Reactのライフサイクル
8章 state
[状態変数, 状態変更関数] = useState(状態変数の初期値)を[現在のstate, 状態更新関数] = useState(状態の初期値)に変更setState(prevState => prevState + 1)のように、状態更新関数に関数を渡すこともできることを説明するための見出しを追加9章 state の更新ロジックを抽出する
10章 Hooksのルール
11章 値の同一性を理解する
12章 副作用を実行する
toTask関数を実装する課題のようになっていて、身につけて欲しい内容ではないと思ったため。13章 その他のHooks関数
14章 描画パフォーマンスの最適化
why_need_react
その他