'use client'; import { FC, forwardRef, useCallback, useState } from 'react'; import clsx from 'clsx'; import Image from 'next/image'; import { useFormContext, useWatch } from 'react-hook-form'; export const Checkbox = forwardRef void; variant?: 'default' | 'hollow'; }>((props, ref: any) => { const { checked, className, disableForm, variant } = props; const form = useFormContext(); const register = disableForm ? {} : form.register(props.name!); const watch = disableForm ? undefined : useWatch({ name: props.name!, }); const [currentStatus, setCurrentStatus] = useState(watch || checked); const changeStatus = useCallback(() => { setCurrentStatus(!currentStatus); props?.onChange?.({ target: { name: props.name!, value: !currentStatus } }); if (!disableForm) { // @ts-ignore register?.onChange?.({ target: { name: props.name!, value: !currentStatus } }); } }, [currentStatus]); return (
{currentStatus && ( Checked )}
); });