Skip to content

Commit ead7775

Browse files
Alan NorbauerVilém Jeniš
authored andcommitted
Fix React warnings (facebookarchive#2221)
Summary: **Summary** Fix instances of the React warning: ``` React.jsx: Spreading a key to JSX is a deprecated pattern. ' + 'Explicitly pass a key after spreading props in your JSX call. ' + 'E.g. <ComponentName {...props} key={key} />' ``` originating from [React here](https://github.com/facebook/react/blob/18d2e0c03e4496a824fdb7f89ea2a3d60c30d49a/packages/react/src/ReactElementValidator.js#L366-L373) This warning occurs when you spread a key with other props. There are probably more instances of this issue but these are the highest firing in our codebase. **Test Plan** `npm run lint && npm run test` Pull Request resolved: facebookarchive#2221 Reviewed By: mitermayer Differential Revision: D18038272 Pulled By: steveluscher fbshipit-source-id: 736236601ace92ae1e8d127e10bb35e393fa14b7
1 parent 42a9d8b commit ead7775

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/component/base/DraftEditor.react.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
352352
customStyleFn,
353353
editorKey: this._editorKey,
354354
editorState,
355-
key: 'contents' + this.state.contentsKey,
356355
textDirectionality,
357356
};
358357

@@ -420,7 +419,10 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
420419
all DraftEditorLeaf nodes so it's first in postorder traversal.
421420
*/}
422421
<UpdateDraftEditorFlags editor={this} editorState={editorState} />
423-
<DraftEditorContents {...editorContentsProps} />
422+
<DraftEditorContents
423+
{...editorContentsProps}
424+
key={'contents' + this.state.contentsKey}
425+
/>
424426
</div>
425427
</div>
426428
</div>

src/component/contents/DraftEditorContents-core.react.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ class DraftEditorContents extends React.Component<Props> {
174174
decorator,
175175
direction,
176176
forceSelection,
177-
key,
178177
offsetKey,
179178
selection,
180179
tree: editorState.getBlockTree(key),
@@ -225,7 +224,7 @@ class DraftEditorContents extends React.Component<Props> {
225224
const child = React.createElement(
226225
Element,
227226
childProps,
228-
<Component {...componentProps} />,
227+
<Component {...componentProps} key={key} />,
229228
);
230229

231230
processedBlocks.push({

0 commit comments

Comments
 (0)