Skip to content

Default Values not working as expected #7058

Answered by ritikbanger
vikas990 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, Default values will not work if you are using a custom component, though you can pass them using states like this:

const { user: user_temp } = useSelector((states: any) => states.authReducer)
const [user, setUser] = useState(user_temp)

i.e. here user_temp contains the default values.
and then use them like this:

const methods = useForm({
    defaultValues: useMemo(() => {
      return user
    }, [user]),
    resolver: yupResolver(validationSchema(translation)),
  })

  const {
    handleSubmit,
    reset,
    register,
    formState: { errors },
  } = methods

Replies: 3 comments 14 replies

Comment options

You must be logged in to vote
1 reply
@vikas990
Comment options

Comment options

You must be logged in to vote
13 replies
@vikas990
Comment options

@vikas990
Comment options

@ritikbanger
Comment options

@vikas990
Comment options

@vikas990
Comment options

Answer selected by vikas990
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants