Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Passing Checkbox value via react-hook-form v5 Controller

I am working on a website that has been built with react-hook-form v5 and am coming across issues with passing the value of Checkbox via submit where it is sent as undefined.

Here is the code - Form.tsx:

import { Controller, useForm } from 'react-hook-form';

export interface FormProps {
  onSubmit: (data: any) => void;
  validationSchema: any;
  defaultValues: any;
}

const Form = (props: FormProps): JSX.Element => {
  const { handleSubmit, errors, control, register, formState, watch, reset } = useForm({
    defaultValues: props.defaultValues,
    validationSchema: props.validationSchema,
  });

  return (
    <form onSubmit={handleSubmit(props.onSubmit)}>
      <CheckboxController 
        control={control} 
        checked={oneNot} 
        label={"Check 1"} 
        name="check1" 
        handleChange={handleCheckbox} 
      />
      <SubmitButton />
    <form />
  );
};

export default Form;

CheckboxController.tsx:

import * as React from 'react';
import { Controller, Control } from 'react-hook-form';
import Checkbox from '@material-ui/core/Checkbox';

import styled from 'styled-components';


export interface CheckboxProps {
  control: Control;
  checked: boolean | undefined;
  label: any;
  name: string;
  handleChange(event: any): any;
}

const CheckboxController = (props: CheckboxProps) => {
  return (
    <Controller as={
        <label>
          <Checkbox 
            checked={props.checked}  
            name={props.name} 
            onChange={props.handleChange}
            />
          {props.label}
        </label>
        } 
        control={props.control}
        name={props.name}
      /> 
  );
};

export default CheckboxController;

When the form is submitted all I receive is check1: undefined

Unfortunately I cannot move from v5 to v7 and was hoping someone may be able to help. I cant quite seem to figure out why it's not working. Cheers.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!