# useValidatedState
This hook is similar to useState but accepts a validator function as first parameter and the initial state value as second, then returns the
state array where the third parameter is result of the validation.
### Why? 💡
- You want to have information on a state validation.
### Basic Usage:
```jsx harmony
import { Input, Space, Typography } from 'antd';
import useValidatedState from 'beautiful-react-hooks/useValidatedState';
const passwordValidator = (password) => password.length > 3;
const ValidatedField = () => {
const [password, setPassword, validation] = useValidatedState(passwordValidator, 'sk8');
return (
setPassword(e.target.value)}
status={!validation.valid && 'error'}
placeholder="Insert password"
/>
{validation.valid ? 'Password is valid' : 'Password is too short'}
);
};
```
### Mastering the hook
#### ✅ good to know:
- useValidatedState does not re-render your component twice to save the validation state.
### Types
```typescript static
/**
* Returns a state that changes only if the next value pass its validator
*/
declare const useValidatedState: >(validator: TValidator, initialValue?: TValue | undefined) => [TValue, (nextValue: TValue) => void, ValidationResult];
export type Validator = (value: TValue) => boolean;
export interface ValidationResult {
changed: boolean;
valid?: boolean;
}
export default useValidatedState;
```