Skip to content

Добавлены три формы на основе модуля react-hook-form#3

Open
coderIvanTS wants to merge 2 commits into
React-js-OTUS:mainfrom
coderIvanTS:ReactHookForms
Open

Добавлены три формы на основе модуля react-hook-form#3
coderIvanTS wants to merge 2 commits into
React-js-OTUS:mainfrom
coderIvanTS:ReactHookForms

Conversation

@coderIvanTS
Copy link
Copy Markdown

No description provided.

const methods = useForm<Inputs>({
resolver: yupResolver(schema as any),
});
const onSubmit = (data: any) => console.log(data);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any это очень критично, если мы используем TS и используем any то теряем весь профит типизации

<div className="goods-form-container">
<label>Наименование товара</label>
<input id="goodsName" {...methods.register("goodsName")} />
{methods.formState.errors.goodsName &&
Copy link
Copy Markdown

@AlexandrLitkevich AlexandrLitkevich Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай те ту использовать диструктуризацию https://react-hook-form.com/get-started .Посмотрите как тут получают данные

export const LoginForm = () => {

const methods = useForm<LoginFormFields>(
{ resolver: yupResolver(validationSchem as any) }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут прекрасная статья которая Вас направит в нужном направлении и избавит от any. https://dev.to/pranavb6/simple-react-hook-form-v7-tutorial-with-typescript-j78

<div>
<label>Логин</label>
<input id="login" {...methods.register("login")} />
{methods.formState.errors.login &&
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Описал что сделать выше

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants