【问题标题】:Exposing React Component PropTypes暴露 React 组件 PropTypes
【发布时间】:2018-09-17 02:03:04
【问题描述】:

我正在 React Native 中开发一些可重用的组件。我已经为组件定义了一些 PropTypes,但是当我将组件发布到我的私有 npm 存储库时,Props Intellisense 不起作用。

例如,如果我定义一个 title propType,当我开始输入 t... 时,我将组件添加到另一个组件它没有向我建议 title。

我该如何解决这个问题?

【问题讨论】:

    标签: reactjs npm components react-proptypes


    【解决方案1】:

    您可以使用增强来做到这一点。只需在增强部分定义您的道具,它们将在您键入时出现在建议中。

    /**
    * @augments {Component<{ title:string, anotherProp:boolean>}
    */
    class MyReactClass extends React.Component {
    
    }
    

    如果您使用的是 vscode,我创建了一个简单的扩展来自动执行此操作。但它需要你定义 propTypes。

    https://marketplace.visualstudio.com/items?itemName=cuneyt-aliustaoglu.vscode-react-proptypes-intellisense

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 2019-11-29
      • 2018-08-13
      相关资源
      最近更新 更多