[Suggestion]: Other method to fix issue rather than depending on useEffect
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
Summary
In Synchronizing with effects section https://react.dev/learn/synchronizing-with-effects inside learn, there's a video section where we show issues in using ref and setting play/pause methods with ref and it raises error
`function VideoPlayer({ src, isPlaying }) {
const ref = useRef(null);
if (isPlaying) {
ref.current.play(); // Calling these while rendering isn't allowed.
} else {
ref.current.pause(); // Also, this crashes.
}
return ;
}`
And below it we say way to solve this is by using useEffect
But rather we can use following way instead to solve the issue. I guess we should tell readers that this can also be possible way but here we'll see how we can solve with useEffect.
`function VideoPlayer({ src, isPlaying }) {
const ref = useRef(null);
if(ref.current !== null){
if (isPlaying) {
ref.current.play(); // Calling these while rendering isn't allowed.
} else {
ref.current.pause(); // Also, this crashes.
}
}
return ;
}`
Page
https://react.dev/learn/synchronizing-with-effects
Details
I think we should show readers this way of solving the null Ref issue. This will help them to understand different ways and correct usecase of useEffect.
Subsection URL - https://react.dev/learn/synchronizing-with-effects
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從連結的 React 文件頁面中的「Synchronizing with Effects」區段及其影片範例開始。將提議的受 ref 保護的替代方案與現有的 useEffect 說明進行比較,然後判斷該頁面是否應該提及它。當文件準確呈現相關選項及其預期使用情境時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100