import { Switch } from 'antd';
import type { SwitchProps } from 'antd';
import { memo, useCallback, useState } from 'react';
interface CustomSwitchProps extends SwitchProps {
  checked: boolean;
  onChange?: (val: boolean) => void;
}
const CustomSwitch = ({ checked: value, onChange, ...others }: CustomSwitchProps) => {
  const [checked, setChecked] = useState<boolean>(value);
  const changeHander = useCallback(
    (val: boolean) => {
      setChecked(val);
      onChange?.(val);
    },
    [onChange],
  );
  return <Switch checked={checked} onChange={changeHander} {...others} />;
};

export default memo(CustomSwitch);
