以编程方式触发反应 dropzone 的 onDrop 功能

问题描述

我正在使用 react dropzone,当文件从另一个组件作为 prop 发送时,我需要以编程方式触发 onDrop 函数。我试过 ref 但这只是暴露了 open 函数

<Dropzone
  multiple={true}
  accept={['application/pdf']}
  onDrop={files =>
    this.handleDrop(files,setFieldValue,setSubmitting)
  }
>
  {({ getRootProps,getInputProps }) => (
    <div
      {...getRootProps()}
      className="drop-border"
    >
      <input
        {...getInputProps()}
      />
      <div>
        Drop a pdf document here or click to select one
      </div>
    </div>
  )}
</Dropzone>

解决方法

你为什么不称它为例如:

componentDidUpdate({ files }) {
    if(files != this.props.files) {
        this.handleDrop(this.props.files,setFieldValue,setSubmitting)
    }
}

?您需要组件 onDrop 吗?