【问题标题】:React Component - Add custom functionality to npm packageReact 组件 - 向 npm 包添加自定义功能
【发布时间】:2017-05-16 17:07:06
【问题描述】:

我有一个看起来像这样的应用程序:

class App extends React.Component {
  constructor (props) {
    super(props)

    this.state = {
      tags: [
        { id: 1, name: "Apples" },
        { id: 2, name: "Pears" }
      ],
      suggestions: [
        { id: 3, name: "Bananas" },
        { id: 4, name: "Mangos" },
        { id: 5, name: "Lemons" },
        { id: 6, name: "Apricots" }
      ]
    }
  }

  handleDelete (i) {
    const tags = this.state.tags.slice(0)
    tags.splice(i, 1)
    this.setState({ tags })
  }

  handleAddition (tag) {
    const tags = [].concat(this.state.tags, tag)
    this.setState({ tags })
  }

  render () {
    return (
      <ReactTags
        tags={this.state.tags}
        suggestions={this.state.suggestions}
        handleDelete={this.handleDelete.bind(this)}
        handleAddition={this.handleAddition.bind(this)} />
    )
  }
}

它基于this npm module. 我不确定我是否遗漏了什么,但是当我输入标签时,虽然我确实看到了弹出的建议,但我也希望能够随时按下TAB 键并自动完成标签的其余部分只剩下一个选项了。类似于stackoverflow标签功能。

我的主要问题是:我如何使用这样的包,通过 npm 安装并扩展其​​功能?我会怎么做才能让它成为我自己的东西,改变周围的东西等等?我不想在我的 npm 模块文件夹中摆弄!

【问题讨论】:

  • 也许你可以分叉它?或者提出拉取请求并合并您的更改?
  • 是的。你应该分叉它并使用 npm 直接从你的 github 安装它或发布你自己的 npm 模块。 npm install --save git+github.com/i-like-robots/react-tags.git
  • 不要分叉它,只需将它包装在一个处理你想要的组件中

标签: javascript reactjs react-native npm tags


【解决方案1】:

您可以分叉插件并将其安装在您的项目中,如下所示

npm i {github_project_link}

如果您想为社区做出贡献。您可以将 PR 提高到原始存储库。

【讨论】:

    猜你喜欢
    • 2019-10-31
    • 2020-12-12
    • 2021-02-23
    • 2020-10-17
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多