简体   繁体   中英

How to trigger the open function for react-dropzone-component using refs?

I am using the react drop-zone component to upload files to the server.

I would like to call the drop-zone open function on button click.

This is what I have tried so far:

I am using refs to reference the drop zone. Also note I have multiple drop-zone's

<DropzoneComponent
  style={{ height: 80 }}
  ref={this.myRef}
  config={config}
  eventHandlers={eventHandlers}
  djsConfig={djsConfig}
  />

And on a separate button click I am calling a function

  openDropZone1 = () => {
    this.refs.myRef.open();
    this.setState({
      bankStatement1: true,
      bankStatement2: false,
      bankStatement3: false
    });
  };

On click of the button I get the following error:-

TypeError: Cannot read property 'open' of undefined on this line this.refs.myRef.open();

Any help or suggestion is most appreciated.

Thank you.

https://github.com/react-dropzone/react-dropzone/tree/master/examples/FileDialog

this is the final answer because it's in the docs if this doesn't solve your problem then it is something wrong with your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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