You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
693B

  1. // form
  2. import { useFormContext, Controller } from 'react-hook-form';
  3. // @mui
  4. import { Switch, FormControlLabel, FormControlLabelProps } from '@mui/material';
  5. // ----------------------------------------------------------------------
  6. type IProps = Omit<FormControlLabelProps, 'control'>;
  7. interface Props extends IProps {
  8. name: string;
  9. }
  10. export default function RHFSwitch({ name, ...other }: Props) {
  11. const { control } = useFormContext();
  12. return (
  13. <FormControlLabel
  14. control={
  15. <Controller
  16. name={name}
  17. control={control}
  18. render={({ field }) => <Switch {...field} checked={field.value} />}
  19. />
  20. }
  21. {...other}
  22. />
  23. );
  24. }