Possible conceptual pitfall when discussing accessing a state variable set in a previous render
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
Hi there!
In this section: https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
It took me a while to understood that prevItems would not be changed until setItems was invoked on it. What tripped me there was that I thought that useState(X) always set items to X on every re-render. Once I understood that prevItems is set to X only when the state is initialized, everything is clear.
This might perhaps be a good place in the docs to clarify (either on a couple of sentences or on its own Pitfall section) that setState will only initialize a value, but not update it during a re-render.
I take this opportunity for congratulating the team on the new React docs. There are one of the best technical documentation pieces I've read in my entire career. 🚀
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
閱讀 React 文件中連結的「Adjusting some state when a prop changes」章節,並檢查其中對跨次 render 的 useState 和 setState 的說明。完成標準是該章節清楚區分 state 的初始初始化與後續更新,並處理所回報的誤解。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100