material-ui - react-hook-form + materialUI + 是的:需要如何制作文件
问题描述
我有
const validationSchema = Yup.object().shape({
photo: Yup.mixed().required("File is required"),
});
const {
control,
handleSubmit,
formState: { errors },
reset,
setError,
} = useForm({
resolver: yupResolver(validationSchema),
});
以及使用材质 UI 进行文件输入的代码
{/********************************************************
PHOTO
*********************************************************/}
<Controller
type="file"
name="photo"
control={control}
render={({ field }) => (
<TextField
inputRef={field.ref}
fullWidth
label="photo"
margin="dense"
accept="image/*"
type="file"
onChange={(e) => {
field.onChange(e.target.files);
handleChange(e);
}}
InputLabelProps={{
shrink: true,
}}
error={errors.photo ? true : false}
/>
)}
/>
<Typography variant="inherit" color="textSecondary">
{errors.photo?.message}
</Typography>
解决方案
推荐阅读
- azure-devops - 仪表板上的查询结果小部件不允许我放大工作项的详细信息
- android - 无法重新订阅 observable
- php - Why store data with a relationship in Laravel?
- c# - 选择不包含命名空间的 XML 节点
- java - new ClassName[0] 有什么作用?(Java 8)
- laravel - Laravel - 每日收入问题
- swift - 在情节提要自动布局中查看依赖项/引用
- javascript - 创建自定义 json 对象
- php - 带有 2 个数据库的 Symfony 表单
- python-3.x - 如何使用所有列创建频率矩阵