Render Props and PureComponent docs question/improvement opportunity
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
In the above link, the last section ("Caveats") talks about how one can avoid killing PureComponents benefits by pulling the render prop function out into an instance method. I understand why this is the case; the 'anonymous' function 'pointer' would change every render, so it isn't seen as something that didn't change, and the PureComponent would re-render all the time.
However, it says you can't do that with a PureComponent if the instance method / render prop needs to reference the component's state/props:
In cases where you cannot define the prop statically (e.g. because you need to close over the component's props and/or state)
<Mouse>should extendReact.Componentinstead.
I don't really understand why that is a limitation, so I'm proposing this as both a question and a suggestion for an update to the docs. I've never used or really looked into PureComponent, but from a look at the docs for them it seems like they re-render if a shallow comparison of it's props/state shows a difference. If that's the case, why wouldn't an instance function on Mouse that used it's own props/state work with PureComponent? The Mouse would re-render if one changed.
(Is it because the Cat - the child component of the render prop Mouse - wouldn't re-render, even though it's parent would?)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Leggi content/docs/render-props.md, in particolare la sezione finale “Caveats” e le indicazioni relative a PureComponent. Chiarisci perché un metodo di istanza usato come render prop che utilizza props o state viene descritto come incompatibile con PureComponent, compreso se il comportamento di rendering del figlio sia rilevante. Il lavoro è completato quando la documentazione risponde direttamente a questa domanda e spiega la limitazione pertinente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100