如何在vscode中显示反应组件道具的预期值?

问题描述 投票:0回答:1

我试图创建自己的私有组件库。我使用prop-types来显示prop的描述,但是没有显示预期值。我没有看到任何关于这个问题的文档,或者我只是瞎了眼。

这就是我想实现的,就像在 material-ui 中一样。

enter image description here

reactjs visual-studio-code material-ui intellisense react-proptypes
1个回答
1
投票

PropTypes 是用于运行时检查,它与VSCode auto-completeauto-suggestions无关。

获取属性的描述是VSCode的一部分,它从函数参数中获取。

// Will get those props autocomplete
const Component = ({ prop1, prop2, prop3 }) => {}

// Won't get autocomplete
const Component = (props) => {}

对于获取 自动建议 你需要为组件添加类型或使用类型系统,如Typescript和Flow。

参见 类型示例 在Material UI repo中。

参见 相关问题 的做法。

© www.soinside.com 2019 - 2024. All rights reserved.