【问题标题】:vs code - custom jsx intelisense with es6vs 代码 - 使用 es6 自定义 jsx 智能感知
【发布时间】:2018-09-17 06:59:06
【问题描述】:

我有一个小型内部库,想为将要使用 JSX 的用户创建智能感知。

基本上,我希望用户开始写作并拥有他需要在自动完成中添加的可用属性。

类型脚本具有允许它显示智能感知的接口和模型。 我正在寻找相同的(即使我需要付出一些努力)

我正在使用 es6 和最新的 vs 代码。

代码并不是特别相关(可以是任何反应代码),但如果有人会给我指导/修改,就在这里。

代码示例:

class Button extends React.Component{
    constructor(props){
    super(props);
  }
  handleClick = () => {
    this.props.onClickFunction(this.props.IncrementValue);
  }
    render(){
    return (
        <button onClick={this.handleClick}>{this.props.IncrementValue}</button>
    )
  }
}
const Result = (props) => {
    return (
    <div>{props.counter}</div>
  );
};
class App extends React.Component{
    state = {counter: 0};

  incrementCounter = (IncrementValue) => {
    this.setState((prevState)=>({
        counter: prevState.counter + IncrementValue
    }));
  };

    render(){
    return(
        <div>
          <Button IncrementValue={1} onClickFunction={this.incrementCounter} />
        <Button IncrementValue={5} onClickFunction={this.incrementCounter} />
          <Button IncrementValue={10} onClickFunction={this.incrementCounter} />
          <Button IncrementValue={100} onClickFunction={this.incrementCounter} />
        <Result counter={this.state.counter} />
        </div>
    )
  }

}

ReactDOM.render(<App />, mountNode);

【问题讨论】:

  • 欢迎来到 SO。您能否分享您迄今为止尝试过的代码,以便我们帮助您解决问题
  • 您的问题与您分享的代码无关。也就是说,基本上,我希望用户开始写作并拥有他需要在自动完成中添加的可用属性。
  • 确切地说,在打字稿中,您有定义结构的接口,而我只是某种适用于 es6 和 jsx 的“接口”(我不介意它是否是 vs 代码功能/扩展.. .)

标签: reactjs autocomplete visual-studio-code intellisense jsx


【解决方案1】:

打开你的 VS Code workspace settings,然后在 settings.json 中添加以下内容。

{
  "files.associations": {
    "*.js": "javascriptreact"
  },
  "editor.formatOnSave": true
}

这将使 VS Code 能够使用特定配置/自动完成功能来处理 React 项目下的每个 js/jsx 文件。 这也将启用保存时的默认代码格式。

希望这会有所帮助!

【讨论】:

  • 嘿,感谢您的努力,但我尝试实现的是智能感知,它知道 jsx 组件应该获取的标签(甚至在道具上添加描述),但它很好无论如何,这在设置中:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2019-07-26
相关资源
最近更新 更多