Passing Arguments to Event Handlers using data-*
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
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.
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
Inizia dalla pagina di documentazione handling-events e rivedi i due pattern esistenti per passare argomenti ai gestori degli eventi, quindi considera l’approccio data-* proposto insieme alla issue React collegata. Il lavoro è completato quando la pagina raccomanda o rifiuta chiaramente questa variante e spiega il motivo.
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
- Da chiarire
- Idoneità per principianti
- 35/100