Skip to content

How to use react-hook-form Controller with the new Mui (V6) Date picker? #10135

Answered by Sajarin-M
itayperry asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the Controller component, like:

const { control, handleSubmit } = useForm({
  defaultValues: {
    date: null as Dayjs | null
  }
});

/*........*/

<Controller
  control={control}
  name="date"
  rules={{ required: true }}
  render={({ field }) => {
    return (
      <DateTimePicker
        label="Date"
        value={field.value}
        inputRef={field.ref}
        onChange={(date) => {
          field.onChange(date);
        }}
      />
    );
  }}
/>

CSB Demo

Replies: 7 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@itayperry
Comment options

@Sajarin-M
Comment options

Answer selected by itayperry
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

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