-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
jsx-handler-names, stateless components and object destructuring #1531
Comments
Try |
@ljharb I did solve it by changing the code as I said but the point is: that code shouldn't yield an error, should it? The same object destructuring works without any trick in normal components. |
Ah, fair point. If the same code (with The bug might be that the SFC warns, or that the stateful component doesn’t warn, but either way they should behave the same. |
My mistake: the message happens with a stateful component too. Actually, it happens even if not destructuring the object: In other words, the rule always accepts a I think it's a bug because if |
It shouldn't be acceptable in general because flat props are way better than nested ones :-) However, I agree that it should be equally acceptable to this rule. |
@ljharb Any updates on this issue? |
@acherkashin no; but a PR with failing tests would be very helpful. |
It seems like this can be covered by setting |
I don't understand how setting AFAIK,
What if I want to code like this
|
@riteshjagga what's the issue with doing that? (besides that components shouldn't be arrow functions) |
Upon using this i.e. destructuring
I get this issue, which should not be reported
If I set
For the besides part, as far as what I've read, this is more of a stylistic preference which is project specific. Please let me know if there is any other reason. |
It's indeed stylistic, and if you prefer That said, if setting it to |
It is not reporting I tried to inspect jsx-handler-names code to see what is happening:
Please let me know what do you think? |
Right, i expect them all not to warn if it’s set to false. If you want the prefix “on” you’d need to set it to that. |
Sorry, I'm confused.
It seems this is desired
This is what you suggested above and closed the bug and I took it as a solution to what is reported. So both these look contradictory. Am I wrong in understanding the conversation? Also if you can let me know if a new bug needs to open for the code situation mentioned in this link. |
Maybe I'm confused :-) are you saying that you want it to warn on |
I do not want but I want |
The rule definitely doesn't - and isn't intended to - differentiate based on whether it comes from props or not. If the prop is named |
OK. Thank you! |
I believe this rule doesn't work with destructuring because when you destructure you are creating a local variable. This produces and error. export function Component({onClick}) {
return (
<Button
onClick={onClick}
>
Click Me
</Button>
);
} This works fine. export function Component(props) {
return (
<Button
onClick={props.onClick}
>
Click Me
</Button>
);
} If you destructure you will unfortunately have to rename on destructure in order for it to work. export function Component({onClick: handleClick}) {
return (
<Button
onClick={handleClick}
>
Click Me
</Button>
);
} Configuration "react/jsx-handler-names": [
"error",
{
"checkInlineFunction": true,
"checkLocalVariables": true
}
], |
Yes, forcing you to rename on destructure is the intended consequence of the rule here. |
I'm seeing something related to #346 in my eslint errors:
I solved it by changing the code, but shouldn't it work considering input is just a prop?
The text was updated successfully, but these errors were encountered: