Javascript 反应:如何继承PropTypes?

Javascript 反应:如何继承PropTypes?,javascript,reactjs,material-ui,react-router-dom,react-proptypes,Javascript,Reactjs,Material Ui,React Router Dom,React Proptypes,我有一个用于反应路由器Dom和材质UI的包装器组件: 从“@material ui/core/Button”导入按钮; 从“React”导入React; 从“react router dom”导入{Link as RouterLink}; const forwardedLink=React.forwardRef((props,ref)=>( )); 功能链接(道具){ 返回( {props.children} ); } Link.propTypes=/? 导出默认链接; 如何从按钮中提供链接道

我有一个用于反应路由器Dom和材质UI的包装器组件:

从“@material ui/core/Button”导入按钮;
从“React”导入React;
从“react router dom”导入{Link as RouterLink};
const forwardedLink=React.forwardRef((props,ref)=>(
));
功能链接(道具){
返回(
{props.children}
);
}
Link.propTypes=/?
导出默认链接;
如何从
按钮
中提供
链接
道具类型

哎呀。。对不起,一开始我没看到你在试图获取 节点模块中的PropType。无论如何如果有人需要这个 在自己的组件中继承propTypes我留下答案*

这适用于我(使用我自己的组件) 将道具导出为常量,并将其指定给继承对象和继承对象中的component.propTypes

注意,首先我犯了一个我没有看到的错误。我忘记在所有内部对象上使用形状,如下所示:

上面是错误的,下面是正确的


Link.propTypes=Button.propTypes
?@zerkms不幸的是,这不起作用。什么是“不起作用”确切的意思?这意味着组件没有得到
propTypes
查看这篇文章,如果你主要是为了intellisense使用propTypes,它可能会对你有所帮助,我只是偶然发现了它,特别是“技巧”部分和“添加@augments”的解释{Component}在组件的JSDoc中,您将向类组件添加完整的PropTypes建议:-如果它不能解决这个问题,它可能会向您指出一个方向=)您好,谢谢您的回答。是的,您是对的,我想知道如何从本机标记继承。这个答案可能仍然对希望继承自定义道具类型的人有帮助
export const configurationPropTypes = {  
  id: PropTypes.string,
  // note: PropTypes.shape not wrapping the 'os' object
  os: {
      version: PropTypes.string,
      locale: PropTypes.string
  }
};

//component being inherited 'ConfigurationListItem.js'
export const configurationPropTypes = {  
  id: PropTypes.string,
  os: PropTypes.shape({
      version: PropTypes.string,
      locale: PropTypes.string
  })
};

ConfigurationListItem.propTypes = configurationPropTypes;
//in 'QueueListItem.js', the component using ConfigurationListItem and inheriting it's propTypes

import ConfigurationListItem , {configurationPropTypes}from './ConfigurationListItem';
//...
QueueListItem.propTypes = {
  id: PropTypes.string.isRequired,
  name: PropTypes.string.isRequired,
  configurations: PropTypes.arrayOf(PropTypes.shape(configurationPropTypes))
}