如何在 vscode 中添加属性智能感知

how to add properties intellisense in vscode

我有一个自定义按钮组件,这就是我在 React 本机项目中使用它的方式

<ButtonPressable
  text="Login"
  borderRadius="20"
  alignSelf="stretch"
  svg={RightArrowSvg}
/>;

这里有 textsvg 和其他 18 个属性。目前我正在参考我写的作弊sheet来编写所有属性。

为什么要向 vscode 添加智能感知,以便在我按下 alt+enter 时它应该显示自定义组件具有的所有 18 个属性。

答案是React Prototypes

完全按照这一步

  • 将其添加到组件文件的顶部
import PropTypes from 'prop-types';

/**
@extends {React.Component<ButtonPressable.protoTypes>}
*/
  • 在底部 class 之后或任何你觉得更漂亮但在 class 之外的地方添加这个 ButtonPressable
ButtonPressable.protoTypes = {

  /** text to be displayed on button */
  text: PropTypes.string.isRequired,

  /** changes text color */
  color: PropTypes.string.isRequired,

}

就是这样,知道您可以通过按 ctrl + space

访问这些带有描述的道具