Passing Arguments to Event Handlers using data-*
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
Currently the documentation https://reactjs.org/docs/handling-events.html mentions two ways how to handle events when the event handler function needs a parameter:
<button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button>
<button onClick={this.deleteRow.bind(this, id)}>Delete Row</button>
As far as I understand, both variants create a new function on each render, which might lead to performance issues because of unnecessary re-renders (you might have to implement custom logic in shouldComponentUpdate). In the documentation:
We generally recommend binding in the constructor or using the class fields syntax, to avoid this sort of performance problem.
Not mentioned is using a "data'*" HTML attribute and then use that event property in the handler.
I would like to document this variant – or if it is not recommended, document that (and why) this is not recommended.
See also https://github.com/facebook/react/issues/1259
If you consider this worth documenting I will create a PR.
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
Comece pela página de documentação handling-events e revise os dois padrões existentes para passar argumentos aos manipuladores de eventos; em seguida, considere a abordagem data-* proposta junto com a issue do React vinculada. Está concluído quando a página recomendar ou rejeitar claramente essa variante e explicar o motivo.
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
- Precisa de esclarecimento
- Facilidade para iniciantes
- 35/100