React-Redux Form和Dropzone onDrop集成

时间:2018-10-29 16:03:57

标签: reactjs react-redux redux-form dropzone.js

我正在尝试使用Redux-Forms从Dropzone触发onDrop事件。当前,在删除文件时,它不会触发事件,但是在您手动选择要上传的文件时,它确实会触发该事件。下面是代码:

const renderDropZone = ({ input, className }) => {
const file = input.value[0];

return (
    <div>
        <Dropzone
            accept="image/*, application/pdf, application/msword"
            onDrop={filesToUpload => input.onChange(filesToUpload)}
            multiple={false}
            className={className}
            {...input}
        >
            {({ isDragAccept, isDragReject }) => {
                if (isDragAccept) return "Allowed"; 
                if (isDragReject) return "File type not allowed";
                return input.value[0] ? `File ready for upload: ${input.value[0].name}` : "Click or drop file here...";
            }}
        </Dropzone>
        <div>
            <h1>{file ? file.name : 'Upload a file'}</h1>
        </div>
    </div>
)
}

有人遇到这个问题吗?

0 个答案:

没有答案