Javascript 为组件中的错误提供更好的调试控制台输出
新的react 0.14无状态组件很好。但是,当其渲染方法中出现错误时,react仅将其打印到控制台:Javascript 为组件中的错误提供更好的调试控制台输出,javascript,reactjs,react-jsx,stateless,Javascript,Reactjs,React Jsx,Stateless,新的react 0.14无状态组件很好。但是,当其渲染方法中出现错误时,react仅将其打印到控制台: Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: Mon Nov 23 2015 06:00:00 GMT+0100 (Central Europe Standard Time)). If you meant to render a collection of childr
Uncaught Error: Invariant Violation: Objects are not valid as a React child
(found: Mon Nov 23 2015 06:00:00 GMT+0100 (Central Europe Standard Time)). If
you meant to render a collection of children, use an array instead or wrap the
object using createFragment(object) from the React add-ons. Check the render
method of `StatelessComponent`.
有没有办法用
displayName
注释组件?通过尝试将displayName
添加到组件函数中,找到了解决方案,如下所示:
const component = (props) => {
return (<div />)
}
component.displayName = "MyComponent"
module.exports = component
const组件=(道具)=>{
返回()
}
component.displayName=“MyComponent”
module.exports=组件
然后,按原样智能反应,将使用此displayName
。这正是你所期待的伟大的反应库;)