Allow exceptions to "jsx-no-lambda" rule
See original GitHub issueI think the usage of lambdas in ref
attributes can warrant an exception from the “jsx-no-lambda” rules, since this is an easy way to get type-safe access to rendered elements.
The only alternative I see would be to create instance functions which would be cumbersome to write and still have to be bound using .bind(this)
.
So until we have a nicer way to generate these “bindings” for example using macros, it would be nice to allow lambdas on some attributes.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Non lambda in React-Router V4 render function - Stack Overflow
@melbil This is not a typescript issue You can pass lambdas, the language allows it. You just have a rule in tslint (which...
Read more >Typescript and React: Lambdas are forbidden? - Jon Hilton
One of those rules is called jsx-no-lambda. Here's the explanation (taken from the GitHub Repo). Creating new anonymous functions (with either ...
Read more >Lambda expressions (since C++11) - cppreference.com
Dynamic exception specifications (until C++20) ... A lambda expression can use a variable without capturing it if the variable.
Read more >Lambda event filtering - AWS Documentation
Lambda throws an exception at the time of the event source mapping creation or update. The filter pattern for data properties must be...
Read more >Rules - ESLint - Pluggable JavaScript Linter
Rules in ESLint are grouped by type to help you understand their purpose. ... of optional chaining in contexts where the `undefined` value...
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 Free
Top 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
Doesn’t that result in the same issues as any other lambda in a JSX prop? Personally I like using a pattern like this for ref handlers:
@JKillian any thoughts on a whitelist of exceptions for this rule?
A whitelist seems like unnecessary extra complexity to me. If a lamda is needed, it can be declared and initialized before the JSX code.
As far as the case of
ref
, there’s no need to recreate the lambda on every render, which is exactly what this rule is trying to prevent. Something like the code example above (the object literal isn’t necessary) works well.