- 我很反应。
- 你能告诉我为什么会发出以下警告
警告:propType失败:提供给swimmingSnapshot
的{{1}}类型的道具function
无效,预计为LaptopHandling
。检查object
的呈现方法。
- 我添加了这个新道具swimSnapshot:React.PropTypes.object.isRequired,
- 在这个道具之后我才得到它。
- 你们能告诉我如何解决它吗?
- 在下面提供我的代码。
Connect(LaptopHandling)
答案 0 :(得分:0)
正如您的LaptopHandling.propTypes
所说:
swimmingSnapshot: React.PropTypes.object.isRequired,
这意味着swimmingSnapshot
正在使用object
,但却传递了function
。
问题出在您的connect
。
export default connect(state => ({
data: state.swimmingSnapshot,
goalDetails: state.goalDetails,
swimmingInfo: state.swimmingInfo,
profile: state.template.profile,
swimmingSnapshot: React.PropTypes.object.isRequired, ----> X
swimmingPositions: React.PropTypes.object.isRequired, ----> X
swimmingPerformance: React.PropTypes.object.isRequired, ----> X
player: state.player
}))(LaptopHandling);
我标记为“X”的所有属性都从React传递propType
函数,这是完全出乎意料的。
你可能想要这样的东西:
export default connect(state => ({
data: state.swimmingSnapshot,
goalDetails: state.goalDetails,
swimmingInfo: state.swimmingInfo,
profile: state.template.profile,
swimmingSnapshot: state.swimmingSnapshot,
swimmingPositions: state.swimmingPositions,
swimmingPerformance: state.swimmingPerformance,
player: state.player
}))(LaptopHandling);
确保state
下面包含所有这些密钥。另外我注意到data
和swimmingSnapshot
具有相同的值,您可能只需要其中一个。