3 ms·
> How can I do this without defining a function? You do define a function, but only once. Constructor: this.smth = this.smth.bind(this); JSX: <button o
by minitech 8y ago
> How can I do this without defining a function?
You do define a function, but only once. Constructor:
this.smth = this.smth.bind(this);
JSX:
<button onClick={this.smth}></button>
Kind of awkward, but the standard practice last I checked. Arrow methods (terminology?) are also something you can add to the language that does the equivalent of .bind() replacements.