Skip to main content

Function: useFormFieldToggle()

useFormFieldToggle(fieldPath): object

Defined in: hooks/useFormFieldToggle.ts:32

Hook to manage boolean toggle fields. This hook provides a simple way to handle boolean fields with toggle functionality.

Parameters

fieldPath

string

Dot notation path to the boolean field

Returns

object

Object containing current value and toggle function

value

value: boolean

toggleValue()

toggleValue: () => void = handleToggleValue

Returns

void

Example

const ToggleField = () => {
const { value, toggleValue } = useFormFieldToggle('isActive');

return (
<label>
<input
type="checkbox"
checked={value}
onChange={toggleValue}
/>
Active
</label>
);
};