[Beta] Using the structuredClone() for updating a nested object
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
https://beta.reactjs.org/learn/updating-objects-in-state#updating-a-nested-object
I think that deep cloning object with structuredClone() and putting the clone into setPerson() is better solution for the problem than using the spread operator.
The the example that was provided can easily be changed this way:
personCopy = structuredClone(person);
personCopy.artwork.city = "New Delhi";
setPerson(personCopy);
This can help avoiding the mistake when spread operator is used to deep clone objects. See example below:
const original = { a: { b: 1 } };
const falseCopy = { ...original };
falseCopy.a.b = 2;
console.log(falseCopy); // logs {a: {b: 2}}
console.log(original); // also logs {a: {b: 2}}
I am sorry if I have failed to follow contributing guidelines. I am aware that the second example is not the best representation of my point.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從連結的 React 文件章節「Updating a nested object」開始,並結合 structuredClone() 提案檢視目前使用展開運算子的範例。完成的標準是:該章節清楚呈現所選擇的更新方式,並避免讓讀者誤解淺層複製與深層複製的差異。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 38/100