reactjs / reactjs/react.dev

Render Props and PureComponent docs question/improvement opportunity

オープン
#825 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

https://github.com/reactjs/reactjs.org/blob/b4b68460e2377837df6e1826e77af173dc205f4f/content/docs/render-props.md

In the above link, the last section ("Caveats") talks about how one can avoid killing PureComponents benefits by pulling the render prop function out into an instance method. I understand why this is the case; the 'anonymous' function 'pointer' would change every render, so it isn't seen as something that didn't change, and the PureComponent would re-render all the time.

However, it says you can't do that with a PureComponent if the instance method / render prop needs to reference the component's state/props:

In cases where you cannot define the prop statically (e.g. because you need to close over the component's props and/or state) <Mouse> should extend React.Component instead.

I don't really understand why that is a limitation, so I'm proposing this as both a question and a suggestion for an update to the docs. I've never used or really looked into PureComponent, but from a look at the docs for them it seems like they re-render if a shallow comparison of it's props/state shows a difference. If that's the case, why wouldn't an instance function on Mouse that used it's own props/state work with PureComponent? The Mouse would re-render if one changed.

(Is it because the Cat - the child component of the render prop Mouse - wouldn't re-render, even though it's parent would?)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

content/docs/render-props.md を読み、特に最後の「Caveats」セクションと PureComponent に関するガイダンスを確認してください。props または state を使用するインスタンスの render-prop メソッドが PureComponent と互換性がないと説明されている理由を明確にし、子のレンダリング動作が関係するかどうかも説明してください。ドキュメントがこの疑問に直接答え、関連する制限を説明していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。