[英]react-hook-form material ui file upload not giving FileList
i have an issue with react hook form and material-ui file uploading when submiting the form i got string path of one file instead of FileList instance我在提交表单时遇到了 react hook 表单和 material-ui 文件上传的问题我得到了一个文件的字符串路径而不是 FileList 实例
<Controller
name='attachments'
control={control}
defaultValue=''
render={({ field }) => <input {...field} type='file' multiple />}
/>
full code on codesanbox: codesanbox 上的完整代码:
https://codesandbox.io/s/xenodochial-bhaskara-9vo13?file=/src/App.js https://codesandbox.io/s/xenodochial-bhaskara-9vo13?file=/src/App.js
For it to work, you will have to implement your own onChange
property.要使其正常工作,您必须实现自己的
onChange
属性。 You can use the field.onChange
callback for this purpose and pass it the file list as an argument.为此,您可以使用
field.onChange
回调并将文件列表作为参数传递给它。 Here's how it can be done:这是如何做到的:
<Controller
name="attachments"
control={control}
defaultValue=""
render={({ field }) => (
<input
type="file"
onChange={e => {
field.onChange(e.target.files);
}}
multiple
/>
)}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.