react.js:3640Warning:Eachchildinanarrayoriteratorshouldhaveaunique”key”prop.Checktherendermethodof`UserList`.Seehttps://fb.me/re

程式設計師詩人發表於2017-12-11

react.js:3640 Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of UserList. See https://fb.me/react-warning-keys for more information.
in h3 (created by UserList)
in UserList

加上 key , 如下:

render: function () {
            var createItem = function (u) {
                return (<h3 key={`li_` + u.id}> {u.username + `:` + JSON.stringify(u.roles)}</h3>);
            }
            return (
                    <ul>
                        {this.state.users.map(createItem)}
                    </ul>
            );
        }


相關文章