Skip to content

API Reference

All hooks return typed results. Import options and result types from the package entry:

import type {
  UseValidateFormOptions,
  UseValidateFormResult,
  UseValidateSelectOptions,
  UseValidateSelectResult,
  UseValidateCheckBoxOptions,
  UseValidateCheckBoxResult,
  SelectItem,
} from 'medhira-rn-typescript-hooks';

useValidateForm

Form validation hook for text inputs.

function useValidateForm(options: UseValidateFormOptions): UseValidateFormResult

Options

Option Type Required Default Description
type 'string' \| 'number' Yes Field data type
label string Yes Field label
isRequired boolean Yes Required field
keyboard string No 'default' Keyboard type
minValue number No Minimum value (number type)
maxValue number No Maximum value (number type)
minLength number No Minimum length (string type)
maxLength number No Maximum length (string type)
defaultValue string \| number No Default value
isDisabled boolean No false Disabled state
isEditable boolean No true Editable state
validationPattern RegExp No Validation regex
minValueError string No built-in Min value error
maxValueError string No built-in Max value error
minLengthError string No built-in Min length error
maxLengthError string No built-in Max length error
focusError string No built-in Required-on-focus error
validError string No built-in Validation error
valueChangeCallback (text: string) => void No Value change callback

Result

Property Type Description
label string Field label
value string \| null Current value
required boolean Is required
keyboardType string Keyboard type
defaultValue string \| null Current default value
isValid boolean Is valid
isFocused boolean Is focused
isBlured boolean Is blurred
hasError boolean Has visible error
customError string \| null Error message
inputIsDisabled boolean Is disabled
inputIsEditable boolean Is editable
min number \| undefined Min value/length
max number \| undefined Max value/length
valueChangeHandler (text: string) => void On change
valueFocusHandler () => void On focus
valueBlurHandler () => void On blur
reset () => void Reset state

useValidateSelect

Dropdown/select validation hook.

function useValidateSelect(options: UseValidateSelectOptions): UseValidateSelectResult

Options

Option Type Required Default Description
itemsList SelectItem[] Yes List of items
isRequired boolean Yes Required selection
defaultValue string \| string[] No Default value
multiple boolean No false Allow multiple
min number No 0 Min selections
max number No 100 Max selections
disabled boolean No false Disabled state
validError string No built-in Validation error
minError string No built-in Min error
maxError string No built-in Max error
onChangeValueCallBack (value) => void No Value change callback
onSelectItemCallBack (item) => void No Select item callback
onPressCallBack (item) => void No Press callback
onOpenCallBack () => void No Open callback
onCloseCallBack () => void No Close callback

Result

Property Type Description
open boolean Is open
itemsList SelectItem[] Items list
value string \| string[] \| null Current value
isDisabled boolean Is disabled
setItems (items) => void Set items
setValue (value) => void Set value
setOpen (item?) => void Toggle open
onChangeValueCallBack (value) => void On change handler
onSelectItemCallBack (item) => void On select handler
onPressCallBack (item) => void On press handler
onOpenCallBack () => void On open handler
onCloseCallBack () => void On close handler
min number Min selections
max number Max selections
multiple boolean Is multiple
selectedItems SelectItem \| SelectItem[] \| null Selected items
selectedValues string \| string[] \| null Selected values
isValid boolean Is valid
hasError boolean Has error
customError string \| null Error message
reset () => void Reset state

useValidateCheckBox

Checkbox validation hook.

function useValidateCheckBox(options: UseValidateCheckBoxOptions): UseValidateCheckBoxResult

Options

Option Type Required Default Description
isRequired boolean Yes Required checkbox
value boolean No false Initial checked state
validError string No built-in Error message
checkedColor string No '#000000' Checked color
uncheckedColor string No '#a8a8a8' Unchecked color
disabled boolean No false Disabled state
onChangeCallBack (checked: boolean) => void No Change callback

Result

Property Type Description
color string \| null Current color
inputIsDisabled boolean \| undefined Is disabled
onValueChangeHandler () => void Toggle handler
value boolean Current checked state
isValid boolean Is valid
customError string \| null Error message
hasError boolean Has error
reset () => void Reset state