如何解决具有 react-hook-form 逻辑的可重用输入文件
function InputFileControl({ control,name,initialValue,...rest }) {
const {
field: { ref,...inputProps },fieldState: { invalid,error,isTouched },} = useController({
name,control,rules: { required: true },defaultValue: initialValue,})
return (
<StyledGrid>
<Grid item container>
<input {...inputProps} inputRef={ref} {...rest} />
</Grid>
<Collapse in={invalid}>
<Grid item container>
<StyleDalert severity="error">{error && error.message}</StyleDalert>
</Grid>
</Collapse>
</StyledGrid>
)
}
就用法而言,在声明我的表单的地方,我是这样使用它的:
<InputFileControl control={control} name="file" type="file" />
不幸的是,它不起作用。当我提交表单时,文件只是路径。没有要管理的文件[0]。
接下来我可以尝试什么?
解决方法
我猜你会得到类似 C:\\fakepath\<filename>
这是一个可能的解决方案:React Hook Form with file just submitting fakepath
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。