react-native-ui-lib
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a
33 lines (32 loc) • 1.17 kB
TypeScript
import { Validator } from './types';
import { InputProps } from './Input';
export interface FieldStateProps extends InputProps {
validateOnStart?: boolean;
validateOnChange?: boolean;
validateOnBlur?: boolean;
/**
* A single or multiple validator. Can be a string (required, email) or custom function.
*/
validate?: Validator | Validator[];
/**
* The validation message to display when field is invalid (depends on validate)
*/
validationMessage?: string | string[];
/**
* Callback for when field validity has changed
*/
onChangeValidity?: (isValid: boolean) => void;
}
export default function useFieldState({ validate, validationMessage, validateOnBlur, validateOnChange, validateOnStart, onChangeValidity, ...props }: FieldStateProps): {
onFocus: (...args: any) => void;
onBlur: (...args: any) => void;
onChangeText: (text: any) => void;
fieldState: {
value: string | undefined;
hasValue: boolean;
isValid: boolean;
isFocused: boolean;
failingValidatorIndex: number | undefined;
};
validateField: (valueToValidate?: any) => boolean;
};