简体   繁体   English

React Component - 向 npm 包添加自定义功能

[英]React Component - Add custom functionality to npm package

I have an app which pretty much looks like this:我有一个看起来像这样的应用程序:

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)} />
    )
  }
}

It's based on this npm module.它基于这个 npm 模块。 I am not sure if I am missing something, but when I type in a tag, whilst I do see the suggestions pop up, I would also like to be able to press the TAB key and autocomplete the rest of the tag, whenever there is only one option left.我不确定我是否遗漏了什么,但是当我输入标签时,虽然我确实看到了建议弹出,但我也希望能够按TAB键并自动完成标签的其余部分,只要有只剩下一种选择。 Similar to the stackoverflow tag functionality.类似于 stackoverflow 标签功能。

My main question is this: How could I use a package like this, installed via npm, and extend its functionality?我的主要问题是:我如何使用这样的包,通过 npm 安装,并扩展其功能? What would I do to make this my own, change things around etc.?我该怎么做才能让它成为我自己的,改变周围的东西等等? I do not want to fiddle around in my npm modules folder!我不想在我的 npm 模块文件夹中摆弄!

You can fork the plugin and install it in your project as below您可以分叉插件并将其安装在您的项目中,如下所示

npm i {github_project_link}

If you want to contribute to the community.如果您想为社区做出贡献。 You can raise PR to the origin repo.您可以将 PR 提升到原始存储库。

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

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