reactjs - React Hook 表单和输入类型文件
问题描述
我正在尝试将输入类型文件与 React Hook Form 一起使用。
import { Controller, useForm } from "react-hook-form";
import {
Button,
Form, FormText,
Label,
Input,
} from 'reactstrap';
const Test = () => {
const { handleSubmit, control, setValue, formState: { errors }} = useForm();
// I have other inputs and divs. Just showing the file here
return (
<Controller
name="file"
control={control}
render={({ field }) => (
<Input {...field} type="file" id="file" />
)}
/>
);
}
当我提交表单并检查 data.file 它只有:C:\fakepath\myFile.pdf
const submitForm = (data) => {
console.log(data.file);
}
解决方案
推荐阅读
- reactjs - 使用 django rest 序列化程序将数据添加到多个表
- ruby-on-rails - 无法在 Rails 6 上拯救 ActionDispatch::Http::Parameters::ParseError
- python - 是否有 NetworkX 算法可以找到从源到目标的最长路径?
- python - n 个变量之间的相等性
- c# - ASP.Net 无法将字节值添加到我的 SQL Server
- python - 从同级目录导入功能(__init__ 文件不起作用)
- tensorflow - Pre_trained model work well on ResNet, InceptionNet but unable to run on VGG16 and VGG19
- firebase - 更新firebase实时数据库xamarin表单中的单个数据
- c - 推广 For 和 Malloc 的大小 C
- r - 如何将颜色图例添加到具有不同几何图层的 ggplot?