You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/rules/jsx-key.md
+10
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,16 @@ The following patterns are considered warnings:
47
47
data.map(x=><>{x}</>);
48
48
```
49
49
50
+
### `checkKeyMustBeforeSpread` (default: `false`)
51
+
52
+
When `true` the rule will check if key prop after spread to avoid [createElement fallback](https://github.com/facebook/react/issues/20031#issuecomment-710346866).
53
+
54
+
The following patterns are considered warnings:
55
+
56
+
```jsx
57
+
<span {...spread} key={"key-after-spread"} />;
58
+
```
59
+
50
60
## When not to use
51
61
52
62
If you are not using JSX then you can disable this rule.
message: '`key` prop must before any `{...spread}, to avoid conflicting with React’s new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html`'
errors: [{message: 'Missing "key" prop for element in array. Shorthand fragment syntax does not support providing keys. Use Act.Frag instead'}]
96
+
},{
97
+
code: '[<App {...obj} key="keyAfterSpread" />];',
98
+
parser: parsers.BABEL_ESLINT,
99
+
options: [{checkKeyMustBeforeSpread: true}],
100
+
settings,
101
+
errors: [{message: '`key` prop must before any `{...spread}, to avoid conflicting with React’s new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html`'}]
102
+
},{
103
+
code: '[<App {...obj} key="keyAfterSpread" />];',
104
+
parser: parsers.TYPESCRIPT_ESLINT,
105
+
options: [{checkKeyMustBeforeSpread: true}],
106
+
settings,
107
+
errors: [{message: '`key` prop must before any `{...spread}, to avoid conflicting with React’s new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html`'}]
108
+
},{
109
+
code: '[<div {...obj} key="keyAfterSpread" />];',
110
+
parser: parsers.BABEL_ESLINT,
111
+
options: [{checkKeyMustBeforeSpread: true}],
112
+
settings,
113
+
errors: [{message: '`key` prop must before any `{...spread}, to avoid conflicting with React’s new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html`'}]
114
+
},{
115
+
code: '[<div {...obj} key="keyAfterSpread" />];',
116
+
parser: parsers.TYPESCRIPT_ESLINT,
117
+
options: [{checkKeyMustBeforeSpread: true}],
118
+
settings,
119
+
errors: [{message: '`key` prop must before any `{...spread}, to avoid conflicting with React’s new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html`'}]
0 commit comments