-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Reparei que as versões do pacote YUP e REACT-HOOK-FORM utilizadas no vídeo estão defasadas e instalando as novas versões consegui ajustar o código do AddTodo.tsx e está funcionando:
package.json
"@hookform/resolvers": "^3.0.0",
"react-hook-form": "^7.43.9",
"yup": "^1.0.2"
código
import React, { useContext } from "react";
import { TodoContext } from "../contexts/TodoContext";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup";
import { TodoContextType } from "../contexts/TodoContextType";
type AddTodoForm = {
title: string;
};
const schema = yup
.object()
.shape({
title: yup.string().required("Tarefa inválida"),
})
.required();
const AddTodo = () => {
const { addTodo } = useContext<TodoContextType>(TodoContext);
const {
register,
handleSubmit,
formState: { errors },
} = useForm<AddTodoForm>({
resolver: yupResolver(schema),
});
const onSubmit = (data: AddTodoForm, e: any) => {
addTodo(data.title);
e.target.reset();
window.location.href = "/";
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<h4>Nova tarefa</h4>
<div className='uk-margin uk-width-1-1'>
<input
type='text'
id='title'
placeholder='Nova tarefa...'
className='uk-input'
{...register("title")}
/>
<span>
<small>
<strong className='uk-text-danger'>{errors.title?.message}</strong>
</small>
</span>
</div>
<div className='uk-width-1-1'>
<button type='submit' className='uk-button uk-button-primary'>
Salvar
</button>
</div>
</form>
);
};
export default AddTodo;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels