我们应该为 Redux 状态使用 PropTypes 吗?

Should we use PropTypes for Redux state?

我有一个非常简单的问题,到目前为止我还没有在网上找到任何令人满意的答案。 目前我正在 React 应用程序中添加 PropTypes。所以,它已经实现了 redux,我想知道我是否应该输入检查来自 redux 的状态。

我有一个父组件可以说是 Component1,它呈现三个不同的组件 - 像这样 -

const Component1 = (props) => {
 return (
  <>
    <Component2 someProps={...} />
    <Component3 someProps={...} />
    <Component4 someProps={...} />
  </>
 )
}

export const mapStateToProps = (state) => {
  return { details: state.details }; //should I use proptypes to check type of details? //
};

export default connect(mapStateToProps)(Component1);

在这里键入检查来自 redux 的状态是否有意义?提前致谢。

是的,这是有道理的。因为是道具。而且无论他们来自哪里

const Component1 = (props) => {
 return (
  <>
    <Component2 someProps={...} />
    <Component3 someProps={...} />
    <Component4 someProps={...} />
  </>
 )
}

Component1.propTypes = {
  details: PropTypes.shape({
    name: string,
    age: number
  })
}

export const mapStateToProps = (state) => {
  return { details: state.details }; //should I use proptypes to check type of details? //
};

export default connect(mapStateToProps)(Component1);