简体   繁体   English

有没有办法访问导入组件的propTypes和defaultProps?

[英]Is there a way to access propTypes and defaultProps of an imported component?

When I look at this page, I can see a table containing the propTypes and defaultProps for a component : http://styleguide.pivotal.io/react_components_alerts.html 当我查看此页面时,可以看到包含组件的propTypes和defaultProps的表: http ://styleguide.pivotal.io/react_components_alerts.html

I want to do the same thing for a library I am doing. 我想为正在做的图书馆做同样的事情。

I have a list of component that I can access using 我有一个可以使用的组件列表

import { A, B, C, D } from 'mylib';

Is there a way to access propTypes and defaultProps so I can format the same table automatically ? 有没有办法访问propTypes和defaultProps,以便我可以自动格式化同一张表?

It's just a static property on the component. 这只是组件上的静态属性。 So A.propTypes and A.defaultProps should give you it. 因此, A.propTypesA.defaultProps应该给您它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM