diff --git a/src/hooks/useCheckbox.ts b/src/hooks/useCheckbox.ts index 5d12cd6..ea330c0 100644 --- a/src/hooks/useCheckbox.ts +++ b/src/hooks/useCheckbox.ts @@ -2,6 +2,7 @@ import { ChangeEvent, useCallback, useState } from 'react'; interface CheckboxItem { checked: boolean; + id: number; [key: string]: any; } @@ -22,7 +23,7 @@ const getSelectedCheckboxValueId = >( .map((checkbox) => checkbox.id); return acc; }, - new Object() as Record, + new Object() as Record, ); return selectedCheckboxValue; @@ -32,7 +33,7 @@ const useCheckbox = >( initialValue: T, ) => { const [checkboxValue, setCheckboxValue] = useState(initialValue); - const selectedCheckboxId = getSelectedCheckboxValueId(checkboxValue); + const selectedCheckboxIds = getSelectedCheckboxValueId(checkboxValue); const onResetCheckbox = useCallback((checkboxKey: keyof T) => { setCheckboxValue((prev) => ({ @@ -74,7 +75,7 @@ const useCheckbox = >( return { checkboxValue, - selectedCheckboxId, + selectedCheckboxIds, setCheckboxValue, onChangeCheckbox, onResetCheckbox, diff --git a/src/hooks/useRadio.ts b/src/hooks/useRadio.ts index f9c1146..cd4ad2c 100644 --- a/src/hooks/useRadio.ts +++ b/src/hooks/useRadio.ts @@ -2,6 +2,7 @@ import { ChangeEvent, useCallback, useState } from 'react'; interface RadioItem { checked: boolean; + name: string; [key: string]: any; } @@ -17,7 +18,7 @@ const getSelectedRadioValueName = >( const selectedRadioValue = radioValueKeys.reduce( (acc, key) => { - acc[key] = radioValue[key].find((radio) => radio.checked)?.name; + acc[key] = radioValue[key].find((radio) => radio.checked)?.name || ''; return acc; }, new Object() as Record,