Render Props and PureComponent docs question/improvement opportunity
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- JavaScript
- Estrelas
- 11.8k
- Forks
- 7.9k
- Merge médio
- 1d 11h
- PRs com merge (30d)
- 11
Descrição
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?)
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Leia content/docs/render-props.md, especialmente a seção final “Caveats” e suas orientações sobre PureComponent. Esclareça por que um método de instância usado como render prop que utiliza props ou state é descrito como incompatível com PureComponent, incluindo se o comportamento de renderização do filho é relevante. A tarefa estará concluída quando a documentação responder diretamente a essa pergunta e explicar a limitação relevante.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript, react
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100