在 Redux 组件中使用 PropTypes

Dan*_*ich 3 reactjs redux

我目前使用两个导出语句设置了我的 Redux 连接的 React 组件,以便更容易地对组件进行浅层测试。我刚刚开始实现 propTypes,并且遇到了 Redux 连接组件的问题。

以下是其中之一的示例:

export class SecondaryHeader extends Component {
  constructor(props) {
    super(props)
  }

  render() {
    const { detail, toggleDetail, survivorsActive } = this.props

    return (
      <div className="secondary-header">
        <div className="container-fluid">
          <div className="row">

            <FontAdjust />
            <ColumnTwo detail={detail} survivorsActive={survivorsActive} />
            <ColumnThree detail={detail} toggleDetail={toggleDetail} />

          </div>
        </div>
      </div>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    detail: state.detail,
    survivorsActive: state.journey.survivorsActive
  }
}

SecondaryHeader.propTypes = {
  detail: PropTypes.boolean,
  toggleDetail: PropTypes.func,
  survivorsActive: PropTypes.boolean
}

export default connect(mapStateToProps, actions)(SecondaryHeader)
Run Code Online (Sandbox Code Playgroud)

我在控制台中得到的错误对于所有 propTypes 都是这样的:

prop type `detail` is invalid; it must be a function
Run Code Online (Sandbox Code Playgroud)

有没有人知道让 propTypes 与这个设置一起工作的非密集方式?如果我必须改变它,就这样吧,但我更喜欢一些不会改变我太多的东西。

Tra*_*ite 5

PropTypes.boolean是问题所在。尝试PropTypes.bool