[Suggestion]: Other method to fix issue rather than depending on useEffect
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 11.8k
- Forks
- 7.9k
- Ø Merge
- 1 T. 11 Std.
- Gemergte PRs (30 T.)
- 11
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Abschnitt „Synchronizing with Effects“ und seinem Videobeispiel auf der verlinkten React-Dokumentationsseite. Vergleiche die vorgeschlagene, durch ref geschützte Alternative mit der bestehenden Erklärung von useEffect und entscheide anschließend, ob die Seite sie erwähnen sollte. Als erledigt gilt die Aufgabe, wenn die Dokumentation die relevanten Optionen und ihre vorgesehenen Anwendungsfälle korrekt darstellt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100