import classNames from 'classnames'; import { useFormContext, useWatch } from 'react-hook-form'; import './switch.css'; interface SwitchProps { className?: string; active: boolean; name: string; callback?: () => void; } const Switch = ({ className, name, callback }: SwitchProps) => { const method = useFormContext(); const { onChange, ...rest } = method.register(name); const watchValue = useWatch({ control: method.control, name }) === 'true'; const switchClassName = classNames('input-switch', className); const handleChangeStatus = (e) => { onChange(e); method.setValue(name, e.target.checked); if (callback) { callback(); } }; return ( ); }; Switch.displayName = 'Switch'; export default Switch;