简体   繁体   English

从父组件reactjs清除react-select v2输入字段?

[英]Clear react-select v2 input field from parent component reactjs?

So, I have parent class, where I press button, and then call 'clearValue' method of TagSelector , where I need to clear AsyncCreatableSelect input. 因此,我有一个父类,在这里我按下按钮,然后调用TagSelector 'clearValue'方法,在这里我需要清除AsyncCreatableSelect输入。

TagSelector class: TagSelector类:

export default class TagSelector extends Component {
    constructor(props) {
        super(props);

        this.state = {
            tagDownloaded: []
        };


      clearValue = () => {
        console.log(this.refs.acs);
        console.log("here I need to clear AsyncCreatableSelect"); // comment
      }

    render() {
        return (
            <AsyncCreatableSelect
                ref="acs"
                cacheOptions
                loadOptions={this.promiseOptions}
                isMulti
                defaultOptions={this.state.tagDownloaded}
                onChange={this.handleChange}
            />
        );
    }
}

I read api and know that 'clearValue' prop-method can help, but how - I don't know. 我阅读了api,并且知道“ clearValue”支持方法可以提供帮助,但是如何使用-我不知道。

React Select feature has option to set select box value - to any of the field / reset as well. React Select功能具有将选择框值设置为-的任何字段/重置选项。 Just found below link with working demo , doing reset of select programatically. 刚在下面找到与工作演示的链接,以编程方式进行选择的重置。 Refer it - How to programmatically clear/reset react-select v2? 引用它- 如何以编程方式清除/重置react-select v2? https://codesandbox.io/s/8256j5m3vl https://codesandbox.io/s/8256j5m3vl

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

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