-
-
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-key: does not support spread attributes #613
Comments
This is especially problematic if you're using Downshift (Simplified example) <Downshift>
{({ getItemProps, isOpen }) => (
<ul>
{isOpen
? items.map((item, index) => (
<li
{...getItemProps({
key: item.value,
index,
item,
})}
>
{item.value}
</li>
))
: null
}
</ul>
)}
</Downshift> You would either disable the rule specifically for this, or you would have to rewrite as: <Downshift>
{({ getItemProps, isOpen }) => (
<ul>
{isOpen
? items.map((item, index) => {
const props = getItemProps({
key: item.value,
index,
item,
});
return (
<li
key={props.key}
{...props}
>
{item.value}
</li>
)
})
: null
}
</ul>
)}
</Downshift> This feels very clunky. |
There is an rfc that states: "Deprecate spreading |
Indeed; key and ref should both always be explicit. Closing this as won’t fix. |
@ljharb The RFC seems to hint that |
interesting. either way, key won’t be a normal one :-) |
Are there any good resources out there for understanding why its important to not spread |
Because key is a special prop for React only that components can’t ever receive. |
Thank you! that totally makes sense now. |
If you do
<SomeEl {...{key: 123}}/>
, react/jsx-key will falsely alert.The text was updated successfully, but these errors were encountered: