Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

the onSubmit types do not match React Hook Form with TS

$
0
0

I geting type's problems when I try to use SubmitHandler type to typping onSubmit prop, I'm getting:

Type Error

TS2322: Type 'SubmitHandler<LoginFormValues>' is not assignable to type 'SubmitHandler<FieldValues>'.   Type 'FieldValues' is missing the following properties from type 'LoginFormValues': email, password

Implementation

import {  FieldValues, useFormContext,  SubmitHandler } from 'react-hook-form';import { Pressable, Text } from 'react-native';type ButtonProps = PressableProps & {  onSubmit: SubmitHandler<FieldValues>;};function SubmitButton({ onSubmit, ...RestButtonProps }: ButtonProps) {  const { handleSubmit } = useFormContext();  return (<Pressable {...RestButtonProps} onPress={handleSubmit(onSubmit)}><Text>Submit</Text></Pressable>  );}type LoginFormValues = {  email: string;  password: string;};function LoginForm() {  const handleSubmit: SubmitHandler<LoginFormValues> = ({ email, password }) =>    console.warn(email, password);  return (<SubmitButton title="Sign In" onSubmit={handleSubmit} />  );}

Viewing all articles
Browse latest Browse all 6287

Trending Articles