reactjs / reactjs/react.dev

Deep comparison in PureComponent question

未關閉
#3,909 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
JavaScript
星號
11.8k
分支
7.9k
平均合併
1 天 11 小時
30 天內合併 PR
11

描述

Hello team,

We have a base class for React components that we're beginning to use. It's like PureComponent but does deep comparison of JSON-like values (just objects, arrays, and primitives). The purpose is to avoid re-renders when inputs haven't changed, even when objects/arrays were reconstructed.

import React from 'react';
import { compareObj } from './deepCompare';

export default class PureDeepComponent extends React.Component {
    shouldComponentUpdate(newProps, newState) {
        return !(compareObj(this.props, newProps) && compareObj(this.state, newState));
    }
}

I was surprised that something like this wasn't included in React, and I'm wondering what the team's thoughts are -- was there a good reason for not doing something like this?

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

未確定檔案、測試或進入點。先檢視 issue 中描述的 PureComponent 和 shouldComponentUpdate 行為,然後判斷所需結果是 React API 功能還是文件;在就該範圍和驗收標準達成共識之前,該 issue 尚未完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, react
領域
frontend
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
18/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。