APP内:
<FramesCollection>
<Frames1 speed='1.0' width='auto' zIndex='1' />
<Frames2 speed='1.2' width='auto' zIndex='1' />
<Frames3 speed='1.4' width='auto' zIndex='1' />
<Frames4 speed='1.6' width='auto' zIndex='1' />
<Frames5 speed='2.0' width='auto' zIndex='4' />
<Frames6 speed='2.5' width='auto' zIndex='3' />
<Rails />
</FramesCollection>
在 FramesCollection 中:
render() {
const { selectedItem, menuItems } = this.props.bottomMenu
const col = menuItems.length
const springSettings = { stiffness: 170, damping: 26 };
return (
<aside className='frames-collection' ref='framesCollection'>
{React.Children.map(
this.props.children,
(child, i) => {
if ('speed' in child.props) {
const width = Math.round(child.props.speed * col * 2000)
const style = { width: width, translateX: spring(-width * selectedItem, springSettings) }
return <Motion key={i} style={style}>
{child}
</Motion>
} else {
return child;
}
})
}
</aside>
)
}
代码编译没有错误,但在浏览器中我看到 2 个错误:
警告:道具类型失败: 提供给
children
的道具类型无效,应为。in Motion(由 FramesCollection 创建) in FramesCollection(由 Connect(FramesCollection) 创建) in Connect(FramesCollection)(由 App 创建) in div(由 App 创建) in App(由 Connect(App) 创建)在 Connect(App) 中提供者中的 divobject
Motion
function
和
Uncaught TypeError: this.props.children is not a function at Object.render (Motion.js:235) at ReactCompositeComponent.js:796 at measureLifeCyclePerf (ReactCompositeComponent.js:75) at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:795) at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:822) 在 ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:362) 在 ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:258) 在 Object.mountComponent (ReactReconciler.js:46) 在 ReactDOMComponent.mountChildren (ReactMultiChild. js:238) 在 ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:697)
我究竟做错了什么?