简体   繁体   English

如何使用defaultProps从React组件中提取道具类型?

[英]How do you extract prop types from a React Component with defaultProps?

Exporting Props from a React.Component is easy enough, but how do you properly extract the types the Component is actually using, once defaultProps are taken into account? 从React.Component导出道具很容易,但是一旦考虑了defaultProps ,如何正确地提取组件实际使用的类型? I imagine you could omit keys from Props and then merge with a Partial of defaultProps, but are there any built-in ways of this? 我想您可以从Props中省略键,然后与defaultProps的Partial合并,但是有任何内置方法吗? Flow accomplishes this with React.ElementConfig 流程通过React.ElementConfig完成

您正在寻找:

JSX.LibraryManagedAttributes<typeof MyComponent, MyComponent["props"]>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从组件中提取 proptypes、isRequired 和 defaultProps - react extract proptypes, isRequired and defaultProps from component 你如何从 React 组件中提取特定的 TypeScript prop 类型? - How do you extract a specific TypeScript prop type from a React component? 使用泛型提取反应组件道具类型 - Extract react component prop types with generics React 组件不需要的 prop 是否应该在 defaultProps 内 - Should React component's not required prop be inside defaultProps React组件的DefaultProps结构 - DefaultProps structure for a React component 如何为打字稿中的无状态反应组件定义defaultProps? - How to define defaultProps for a stateless react component in typescript? 如何将组件的类型断言为 prop? - How do you assert the type of a component as prop? 当使用Route render prop而不是Route component prop时,如何访问react-router-dom 4中的url args? - How do you access url args in react-router-dom 4 when using Route render prop instead of Route component prop? 在 React/Jest 单元测试中,你如何模拟被模拟组件调用的事件道具? - In a React/Jest unit test, how do you simulate an event prop being called by a mocked component? 你如何键入一个作为道具传递给组件的 useState 钩子,typescript + react - How do you type a useState hook that is being passed as a prop to a component, typescript+react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM