箭头函数链中的 PropTypes

PropTypes in chain of arrow functions

我正在尝试使用 PropTypes 提高我的应用程序的质量,但我遇到了这种情况:

const withLayout = (customProps) => (PageComponent) => (props) => {
    const { locale } = props.pageContext;
    const {
        localeKey, hideLangs, headerTitle, headerSubtitle, headerImages,
    } = customProps;
    ....
}

这可能没有任何意义。

withLayout.propTypes = {
  pageContext: PropTypes.string.isRequired,
};

如何为此分配 PropTypes?我必须将它解构为三个命名函数吗?

也许这个例子对你有帮助。

const withLayout = (customProps) => {
  const innerFunction = ( WrappedComponent ) => {
       const InnerComponent = ( props ) => <WrappedComponent { ...props } { ...customProps } />

       InnerComponent.propTypes = { /* ... */ }

       return InnerComponent
  }

  innerFunction.propTypes = { /* ... */ }

  return innerFunction
} 

withLayout.propTypes = { /* ... */ }