import { FormControl, FormErrorMessage, FormLabel, Switch } from '@chakra-ui/react' import { SwitchProps } from '@mui/material' import { useField } from 'formik' import { ChangeEvent } from 'react' type SwitchFieldProps = SwitchProps & any & { label: string name: string onSwitchChangeEffect?: () => void } export const SwitchField = (props: SwitchFieldProps): JSX.Element => { const { label, name, onSwitchChangeEffect, ...rest } = props const [field, { error }, { setValue }] = useField({ name }) const handleChange = (e: ChangeEvent) => { setValue(e.target.checked) if (onSwitchChangeEffect) { onSwitchChangeEffect() } } return ( {label} {error && {error}} ) }