Simplify wording of key warning (#14503)
I don't think "array or iterator" is adding anything, and it may well be confusing, especially since this is one of the first and most common warnings that devs see.
This commit is contained in:
parent
3494ee57e6
commit
547e059f0b
|
@ -354,7 +354,7 @@ describe('ReactFunctionComponent', () => {
|
|||
}
|
||||
|
||||
expect(() => ReactTestUtils.renderIntoDocument(<Child />)).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.\n\n' +
|
||||
'Each child in a list should have a unique "key" prop.\n\n' +
|
||||
'Check the render method of `Child`.',
|
||||
);
|
||||
});
|
||||
|
|
|
@ -162,8 +162,8 @@ describe('ReactMultiChildText', () => {
|
|||
['', 'foo', <div>{true}{<div />}{1.2}{''}</div>, 'foo'], ['', 'foo', <div />, 'foo'],
|
||||
]);
|
||||
}).toWarnDev([
|
||||
'Warning: Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Warning: Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Warning: Each child in a list should have a unique "key" prop.',
|
||||
'Warning: Each child in a list should have a unique "key" prop.',
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ if (__DEV__) {
|
|||
child._store.validated = true;
|
||||
|
||||
const currentComponentErrorInfo =
|
||||
'Each child in an array or iterator should have a unique ' +
|
||||
'Each child in a list should have a unique ' +
|
||||
'"key" prop. See https://fb.me/react-warning-keys for ' +
|
||||
'more information.' +
|
||||
getCurrentFiberStackInDev();
|
||||
|
@ -91,7 +91,7 @@ if (__DEV__) {
|
|||
|
||||
warning(
|
||||
false,
|
||||
'Each child in an array or iterator should have a unique ' +
|
||||
'Each child in a list should have a unique ' +
|
||||
'"key" prop. See https://fb.me/react-warning-keys for ' +
|
||||
'more information.',
|
||||
);
|
||||
|
|
|
@ -709,7 +709,7 @@ describe('ReactFragment', () => {
|
|||
|
||||
ReactNoop.render(<Foo condition={false} />);
|
||||
expect(ReactNoop.flush).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
|
||||
expect(ops).toEqual([]);
|
||||
|
@ -753,12 +753,12 @@ describe('ReactFragment', () => {
|
|||
|
||||
ReactNoop.render(<Foo condition={true} />);
|
||||
expect(ReactNoop.flush).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
|
||||
ReactNoop.render(<Foo condition={false} />);
|
||||
expect(ReactNoop.flush).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
|
||||
expect(ops).toEqual(['Update Stateful']);
|
||||
|
@ -766,7 +766,7 @@ describe('ReactFragment', () => {
|
|||
|
||||
ReactNoop.render(<Foo condition={true} />);
|
||||
expect(ReactNoop.flush).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
|
||||
expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
|
||||
|
|
|
@ -126,7 +126,7 @@ function validateExplicitKey(element, parentType) {
|
|||
if (__DEV__) {
|
||||
warning(
|
||||
false,
|
||||
'Each child in an array or iterator should have a unique "key" prop.' +
|
||||
'Each child in a list should have a unique "key" prop.' +
|
||||
'%s%s See https://fb.me/react-warning-keys for more information.',
|
||||
currentComponentErrorInfo,
|
||||
childOwner,
|
||||
|
|
|
@ -320,7 +320,7 @@ describe('ReactChildren', () => {
|
|||
|
||||
let instance;
|
||||
expect(() => (instance = <div>{threeDivIterable}</div>)).toWarnDev(
|
||||
'Warning: Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Warning: Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
|
||||
function assertCalls() {
|
||||
|
@ -905,7 +905,7 @@ describe('ReactChildren', () => {
|
|||
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />),
|
||||
).toWarnDev(
|
||||
'Warning: ' +
|
||||
'Each child in an array or iterator should have a unique "key" prop.' +
|
||||
'Each child in a list should have a unique "key" prop.' +
|
||||
' See https://fb.me/react-warning-keys for more information.' +
|
||||
'\n in ComponentReturningArray (at **)',
|
||||
);
|
||||
|
@ -926,7 +926,7 @@ describe('ReactChildren', () => {
|
|||
ReactTestUtils.renderIntoDocument([<div />, <div />]),
|
||||
).toWarnDev(
|
||||
'Warning: ' +
|
||||
'Each child in an array or iterator should have a unique "key" prop.' +
|
||||
'Each child in a list should have a unique "key" prop.' +
|
||||
' See https://fb.me/react-warning-keys for more information.',
|
||||
{withoutStack: true}, // There's nothing on the stack
|
||||
);
|
||||
|
|
|
@ -259,9 +259,7 @@ describe('ReactElementClone', () => {
|
|||
it('warns for keys for arrays of elements in rest args', () => {
|
||||
expect(() =>
|
||||
React.cloneElement(<div />, null, [<div />, <div />]),
|
||||
).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
);
|
||||
).toWarnDev('Each child in a list should have a unique "key" prop.');
|
||||
});
|
||||
|
||||
it('does not warns for arrays of elements with keys', () => {
|
||||
|
|
|
@ -42,9 +42,7 @@ describe('ReactElementValidator', () => {
|
|||
|
||||
expect(() => {
|
||||
Component(null, [Component(), Component()]);
|
||||
}).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
);
|
||||
}).toWarnDev('Each child in a list should have a unique "key" prop.');
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements with owner info', () => {
|
||||
|
@ -67,7 +65,7 @@ describe('ReactElementValidator', () => {
|
|||
expect(() => {
|
||||
ReactTestUtils.renderIntoDocument(React.createElement(ComponentWrapper));
|
||||
}).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.' +
|
||||
'Each child in a list should have a unique "key" prop.' +
|
||||
'\n\nCheck the render method of `InnerClass`. ' +
|
||||
'It was passed a child from ComponentWrapper. ',
|
||||
);
|
||||
|
@ -84,7 +82,7 @@ describe('ReactElementValidator', () => {
|
|||
expect(() => {
|
||||
ReactTestUtils.renderIntoDocument(<Anonymous>{divs}</Anonymous>);
|
||||
}).toWarnDev(
|
||||
'Warning: Each child in an array or iterator should have a unique ' +
|
||||
'Warning: Each child in a list should have a unique ' +
|
||||
'"key" prop. See https://fb.me/react-warning-keys for more information.\n' +
|
||||
' in div (at **)',
|
||||
);
|
||||
|
@ -96,7 +94,7 @@ describe('ReactElementValidator', () => {
|
|||
expect(() => {
|
||||
ReactTestUtils.renderIntoDocument(<div>{divs}</div>);
|
||||
}).toWarnDev(
|
||||
'Warning: Each child in an array or iterator should have a unique ' +
|
||||
'Warning: Each child in a list should have a unique ' +
|
||||
'"key" prop.\n\nCheck the top-level render call using <div>. See ' +
|
||||
'https://fb.me/react-warning-keys for more information.\n' +
|
||||
' in div (at **)',
|
||||
|
@ -117,7 +115,7 @@ describe('ReactElementValidator', () => {
|
|||
}
|
||||
|
||||
expect(() => ReactTestUtils.renderIntoDocument(<GrandParent />)).toWarnDev(
|
||||
'Warning: Each child in an array or iterator should have a unique ' +
|
||||
'Warning: Each child in a list should have a unique ' +
|
||||
'"key" prop.\n\nCheck the render method of `Component`. See ' +
|
||||
'https://fb.me/react-warning-keys for more information.\n' +
|
||||
' in div (at **)\n' +
|
||||
|
@ -161,7 +159,7 @@ describe('ReactElementValidator', () => {
|
|||
};
|
||||
|
||||
expect(() => Component(null, iterable)).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
'Each child in a list should have a unique "key" prop.',
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -48,9 +48,7 @@ describe('ReactJSXElementValidator', () => {
|
|||
ReactTestUtils.renderIntoDocument(
|
||||
<Component>{[<Component />, <Component />]}</Component>,
|
||||
),
|
||||
).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
);
|
||||
).toWarnDev('Each child in a list should have a unique "key" prop.');
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements with owner info', () => {
|
||||
|
@ -69,7 +67,7 @@ describe('ReactJSXElementValidator', () => {
|
|||
expect(() =>
|
||||
ReactTestUtils.renderIntoDocument(<ComponentWrapper />),
|
||||
).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.' +
|
||||
'Each child in a list should have a unique "key" prop.' +
|
||||
'\n\nCheck the render method of `InnerComponent`. ' +
|
||||
'It was passed a child from ComponentWrapper. ',
|
||||
);
|
||||
|
@ -90,9 +88,7 @@ describe('ReactJSXElementValidator', () => {
|
|||
|
||||
expect(() =>
|
||||
ReactTestUtils.renderIntoDocument(<Component>{iterable}</Component>),
|
||||
).toWarnDev(
|
||||
'Each child in an array or iterator should have a unique "key" prop.',
|
||||
);
|
||||
).toWarnDev('Each child in a list should have a unique "key" prop.');
|
||||
});
|
||||
|
||||
it('does not warn for arrays of elements with keys', () => {
|
||||
|
|
Loading…
Reference in New Issue