react/jsx-no-bind: how to pass args from callbacks?
See original GitHub issueI have a question about react/jsx-no-bind
rule in 3.0.0
: how can I pass args to handler from callback if I can’t use bind and arrow functions?
doSomething(thing) { ... }
render() {
const { items } = this.props;
return (
<ul>
{
items.map(item => (
<li onClick={this.doSomething.bind(this, item)} /> // <--- JSX props should not use .bind()
<li onClick={() => this.doSomething(item)} /> // <--- JSX props should not use arrow functions
))
}
</ul>
);
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:85
- Comments:76 (2 by maintainers)
Top Results From Across the Web
React: how to pass arguments to the callback - Stack Overflow
What you can do is create a partially applied or higher order function to enclose the item.id and pass it along.
Read more >Passing function to components, Callbacks in React, context ...
First things first, if you are new to react, you can have a look at official documentation of passing functions to components here....
Read more >Flexible Callback Signatures | Dash for Python Documentation
Callback functions can register to be called with named keyword arguments. You can do this by passing dictionaries to the inputs and state...
Read more >How can I pass arguments to Tkinter button's callback ...
We will pass the label as the argument in the button command by using lambda function. #Import necessary Library from tkinter import *...
Read more >How to pass a parameter to an event handler or callback
This will help you to understand the underlying logic of event handlers and passing parameters through it. Creating React Project: Step 1: To ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you still want to do it inline, it’s possible to use something like to
_.partial
orThis will pass through the linter, but will still have the issues listed in
eslint-plugin-react#jsx-no-bind
documentation.Right - at that point you might as well disable the rule.