反应给我一个奇怪的错误。似乎不明白最新情况

时间:2017-12-29 03:59:09

标签: reactjs redux

我有一系列用户名和电子邮件。 在父组件中,我像这样循环这个数组

return(<div>{       
                users.map((user)=>{
                    return <UserBox key={user.name} user={user}></UserBox>;   
                })
               }
               </div>
            );

Userbox 是具有此

的子组件
return (
            <p>
                {this.props.user.name} {this.props.user.rating}
            </p>
        );

但是我收到了这个错误

Uncaught Error: Objects are not valid as a React child (found: object with keys {s, e, c}). If you meant to render a collection of children, use an array instead.
    in p (at UserBox.js:15)
    in UserBox (at Users.js:30)
    in div (at Users.js:27)
    in Users (created by Connect(Users))
    in Connect(Users) (at Dashboard.js:18)
    in div (at Dashboard.js:15)
    in div (at Dashboard.js:14)
    in main (at Dashboard.js:13)
    in Dashboard (created by UserIsAuthenticated(Dashboard))
    in UserIsAuthenticated(Dashboard) (created by Connect(UserIsAuthenticated(Dashboard)))
    in Connect(UserIsAuthenticated(Dashboard)) (created by RouterContext)
    in div (at App.js:39)
    in App (created by RouterContext)
    in RouterContext (created by Router)
    in Router (at index.js:33)
    in Provider (at index.js:32)
    at invariant (invariant.js:42)
    at throwOnInvalidObjectType (react-dom.development.js:6748)
    at createChild (react-dom.development.js:7012)
    at reconcileChildrenArray (react-dom.development.js:7282)
    at reconcileChildFibers (react-dom.development.js:7651)
    at reconcileChildrenAtExpirationTime (react-dom.development.js:7756)
    at reconcileChildren (react-dom.development.js:7747)
    at updateHostComponent (react-dom.development.js:7998)
    at beginWork (react-dom.development.js:8229)
    at performUnitOfWork (react-dom.development.js:10224)

1 个答案:

答案 0 :(得分:2)

在您的用户Box组件中:

return (
  <p>
    {this.props.user.name} {this.props.user.rating}
  </p>
);

检查this.props.user.namethis.props.user.rating 字符串,而不是对象