-
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 jsx-no-bind and jsx-no-lambda to ignore DOMComponents #179
Conversation
Thanks for your interest in palantir/tslint-react, @koba04! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
What's the status on this? This is a must-have feature |
@benny-medflyt The last commit of this repo is Jun 2018 and we can't see any activities except a CLA bot. So I guess this repo seems to be no longer maintained. |
@adidahiya @jkillian Any comment? |
Thinking about this some more, the test whether to allow/disallow anonymous functions on props should not be whether or not the component is a DOMCompoment. Instead, the test should be whether the component inherits from React.PureComponent. This is something where tslint has an advantage over eslint since it can utilize the type information to determine this. |
Can someone provide some more documentation or a fleshed out proposal of the overall logic here, possibly with some performance metrics? I'm not sure I understand all the details around this change via the eslint rule you linked... why exactly are DOMComponents ok? |
I can try to explain it the way I understand it. Let's say I have 2 react components: function MyComponent1(props: {}) {
return (
<div>
<ListView
onClick={() => alert("clicked")}
items={myItems}
/>
</div>
);
} function MyComponent2(props: {}) {
return (
<div>
<button
onClick={() => alert("clicked")}
disabled={false}
/>
</div>
);
} When "MyComponent1" is re-rendered, then the ListView will also be considered for re-rendering. If ListView inherits from Now the story of "MyComponent2" is similar, but different. When "MyComponent2" is re-rendered, then the button will also be considered for re-rendering. But since "button" is a DOM element, it will always be re-rendered, no matter what. DOM elements cannot inherit from Note: There may be a tiny performance increase by using a non-arrow function with the button, since react will see that the Thinking about it some more, I the actual distinction we care about for this tslint rule, is not whether or not the React component is a DOM node or not a DOM node. I think what we are really interested in is whether the React component inherits from PureComponent or not (and DOM components fall into the category of those not inheriting from PureComponent). Sometimes you have a fancy custom "Button" element that is just a small wrapper around A tslint rule for disallowing arrow function on props only for components that inherit from |
Ok, thanks for the explanation.
this starts to feel unintuitive... so now I'm going to design my components so that only ones with "complex" render logic are |
@benny-medflyt Thank you for your great explanation! I think that applying the rule to |
Closing due to inactivity and age. See #210 |
I think function binding and anonymous functions with DOMComponent would be fine, the cost to create a function each time is not significant.
So it makes sense to add a option to ignore DOMComponents.
eslint-plugin-react
has added this option as jsx-eslint/eslint-plugin-react#1238