-
Notifications
You must be signed in to change notification settings - Fork 50.2k
Description
Do you want to request a feature or report a bug?
It's more of a bug -- I don't think this behaviour should occur, but it's not a problem in production.
What is the current behavior?
Warning appears.
Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of
List. See https://fb.me/react-warning-keys for more information.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).
Fiddle. I'll paste the code here too, just in case:
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom-server.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>function List(props) {
return <ul>
{props.items.map(x => <li>{x}</li>)}
</ul>
}
let listItems = [...Array(10).keys()];
document.getElementById('container').innerHTML = ReactDOMServer.renderToStaticMarkup(<List items={listItems}/>);What is the expected behavior?
No warning.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Fiddle uses React 15.0.1. Tested in Chrome on Ubuntu. I didn't test previous versions of React, but I suspect it's always been this way.
Notes
If I'm not mistaken, the HTML generated via renderToStaticMarkup cannot be updated by React because the essential DOM attributes are stripped away. This means that keys should not be necessary because React will never need to match up the elements during a re-render. Supplying keys that will never be used just to avoid a warning is tedious. Ergo, warning should be suppressed when JSX is rendered via renderToStaticMarkup.