【问题标题】:how to add properties intellisense in vscode如何在vscode中添加属性intellisense
【发布时间】:2020-09-30 07:22:49
【问题描述】:

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

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

这里有textsvg 和其他 18 个属性。目前我正在通过参考我编写的备忘单来编写所有属性。

有什么理由要在 vscode 中添加智能感知,这样当我按下alt+enter 时,它应该显示自定义组件具有的所有 18 个属性。

【问题讨论】:

  • 不确定 JS。您可以使用 TS 完全用于此目的。
  • @senthilbalaji 我对 ts 不感兴趣,JS 可以。我在其他技术中使用过,比如 Navtivescript,他们有智能感知插件可以做到这一点。
  • 查看 react proptypes,在那里您可以定义可访问的属性 - 通过将智能感知添加到您的 VSCode 这应该添加“自动完成”或“建议”

标签: javascript react-native visual-studio-code nativescript intellisense


【解决方案1】:

答案是React Prototypes

完全按照这一步来

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

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

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

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

}

就是这样,知道你可以通过按ctrl + space来访问这些带有描述的道具

【讨论】:

  • React 很庞大,没有正确的路线!谢谢你的回答。
猜你喜欢
  • 2021-05-06
  • 2018-12-19
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 1970-01-01
  • 2012-08-03
  • 2019-07-25
  • 2020-10-18
相关资源
最近更新 更多