Skip to content
Discussion options

You must be logged in to vote

For future reference, the solution to the question above has three parts.

First, instead of passing control down as a prop to a nested component, you can access the form context with the use of useFormContext. Documentation here.

    imports ...
    const schema = yup.object().shape({...});
    function App() {
      const methods = useForm({
        resolver: yupResolver(schema)
      });
      const { register, handleSubmit, formState: { errors }} = methods;
    
      return (
        <FormProvider {...methods}>
          <form onSubmit={handleSubmit((data) => console.log(data))}>
            <NestedInput/>
          </form>
        </FormProvider>
      );
    }

Second, you need to r…

Replies: 2 comments 1 reply

Comment options

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

Comment options

You must be logged in to vote
0 replies
Answer selected by bluebill1049
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants