警告:propType失败:提供给`LaptopHandling`的类型`function`的prop`swingsSnapshot`无效,

时间:2016-11-29 01:44:37

标签: javascript html css reactjs redux

- 我很反应。 - 你能告诉我为什么会发出以下警告 警告:propType失败:提供给swimmingSnapshot的{​​{1}}类型的道具function无效,预计为LaptopHandling。检查object的呈现方法。 - 我添加了这个新道具swimSnapshot:React.PropTypes.object.isRequired, - 在这个道具之后我才得到它。 - 你们能告诉我如何解决它吗? - 在下面提供我的代码。

Connect(LaptopHandling)

1 个答案:

答案 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下面包含所有这些密钥。另外我注意到dataswimmingSnapshot具有相同的值,您可能只需要其中一个。