简体   繁体   English

使用 Flow.js 做出反应的自定义按钮组件在 vs-code 中的自动完成

[英]Auto-Complete in vs-code for custom button component in react using Flow.js

I am creating a Custom Button component in React.我正在 React 中创建一个自定义按钮组件。 The basic version of the component looks something like this -该组件的基本版本如下所示 -

// @flow

type ButtonPropsType = {};
const Button = (props: ButtonPropsType) => {
  const { children, ...rest } = props;
  return <button {...rest}>{children}</button>
}

let App = () => {
  return (
    <div>
      <Button style={{ margin: 10 }}>Sahil Kapoor</Button>
    </div>
  )
}

How should I define the type of my Button component so that VS-Code knows that my Button component accepts all the attributes of a normal React button element like style, onClick, className etc?我应该如何定义我的 Button 组件的类型,以便 VS-Code 知道我的 Button 组件接受普通 React 按钮元素的所有属性,如样式、onClick、className 等?

you can extend your type from type of HTMLButtonElement class which allows all basic props of button您可以从HTMLButtonElement class 类型扩展您的类型,它允许按钮的所有基本道具

refer here for all the flow types请参阅 此处了解所有流类型

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

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