-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow exceptions to "jsx-no-lambda" rule #26
Comments
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: class Button extends React.Component<{}, {}> {
private buttonElement: HTMLElement;
private refHandlers = {
button: (ref) => this.buttonElement = ref,
...
};
public render() {
return <button ref={this.refHandlers.button} />;
}
} @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 |
Closing, as I don't think we'll take any action here |
@jkillian in react the performance drop with arrow function as prop is due to pure components re-rendering when it could be avoided. The creation on a new function is not a problem. The See: facebook/react#9086 (comment) All React examples I could find recommend the usage of an arrow function in IMO the fact that this rule warns on |
This is a good point. I would accept a PR to whitelist certain props like |
Source: https://reactjs.org/docs/refs-and-the-dom.html#caveats |
@shahan312 did you mesure any actual performance loss related to that? |
@adidahiya wrote:
However #107, just permitted Hard to say how significant the performance impact is that @shahan312 is raising (I'm generally onboard with @testerez's line of thinking), but it seems as reasonable a concern as any I've seen on this topic. My own interest in a whitelist is to allow anonymous functions for With this in mind, I've opened a PR to introduce a configurable whitelist. Please let me know what you think! |
@adidahiya how about the ability to allow on DOM components where he performance implications would be limited? Essentially this suggestion for eslint jsx-eslint/eslint-plugin-react#1238 |
Closing due to deprecation, see #210 |
I 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.
The text was updated successfully, but these errors were encountered: