question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsx-no-lambda and passing args in event handlers

See original GitHub issue

If one never uses lambdas in a jsx arg, how would one pass args to an event handler? For example:

<Foo onClick={ (event) => this.foo(23) }/>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:33
  • Comments:51 (9 by maintainers)

github_iconTop GitHub Comments

90reactions
mohsen1commented, May 14, 2017

You can do onClick={this.foo.bind(this, 23)} but I would question why this is necessary. 23 should be either a prop or part of state.

57reactions
johnsimonscommented, Sep 24, 2017

In ES6 you should be able to use currying, eg:

<Foo onClick={ this.foo(23) }/>

foo = (event) => (id) => {

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing arguments to event handlers in react - Stack Overflow
It's defined somewhere in the React component you're looking at. Find the function definition to see what its arguments are and what it...
Read more >
Day 10: Passing Arguments to Event Handler in React - Medium
Learn how to pass arguments via Arrow Function and Bind Method. Most of the time, we may need to pass arguments to our...
Read more >
Passing Arguments to Event Listeners in JavaScript
Passing arguments to an event handler can be particularly useful when the handler is reused for different events. For example, we want to...
Read more >
Passing Arguments to Event Handlers - TutorialsWebsite
Passing arguments to event handler Using Bind Function or Method. You don't need to pass “e” (React Event Object) as an argument. With...
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:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found