-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Don't warn in react/jsx-props-no-spreading when all properties are listed explicitly. #2439
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
Comments
An option to allow this case sounds great, and does not conflict with the impetus for the rule - that implicit spreading is an antipattern. |
I added #2449, that might help here. I thought for a while about allowing also to handle cases when some given props are assigned to dedicated variable and than spread, e.g.: const modalProps = { prop1, prop2, prop3 };
return <Modal {...modalProps } /> I feel that this could be helpful, yet current implementation is good enough to solve your problem without extending implementation complexity by far. What do you think guys? |
We're currently using Downshift and it's api provides render props that are things like <Downshift
onChange={selection =>
alert(selection ? `You selected ${selection.value}` : 'Selection Cleared')
}
itemToString={item => (item ? item.value : '')}
>
{({
getInputProps,
isOpen,
inputValue
}) => (
<div>
<input {...getInputProps()} /> Not sure how tricky it would be to pickup on cases like this, but thought this might add another element to the conversation here. |
@richardson-trevor there's no good way to pick up on that, and it's debatable whether that's a good pattern anyways. For that case, use an eslint override comment. |
Allowing this would be really useful |
@ljharb reading upstream, it seems scenario of using a dedicated variable and then spread isn't covered? If it is, then 👍 See #2439 (comment) |
No, it's not, but that would only even be possible to handle if the variable is defined in the same file. I'd be open to a PR exploring that, but this issue should stay closed, as it's resolved. |
…explicit spread of props Fixes jsx-eslint#2439.
Does anyone followed up this scenario?
|
A syntactic workaround for avoiding repetition in the following JSX:
..is to instead write:
The reason for react/jsx-props-no-spreading is to encourage being explicit with properties, while allowing exceptions to be configured for Higher Ordered Components. The above example is not a HOC, but is explicit about the properties.
Therefore, there should be a configuration to allow this case ("spreading of an inline object literal that does not itself contain any spreads"), perhaps even as a default.
That said, ideally JSX would provide a nicer non-repetitive syntax for the above.
The text was updated successfully, but these errors were encountered: