props-validator
React Props Validators 🏥
Installation
npm i props-validator
or
yarn add props-validator
Usage
Importing
Either
;
or
const isLength = ;
Implementation
... MyReactComponentpropTypes = name: // checks for the length of the prop value ...
Validators
Validator | Description | Example |
---|---|---|
isLength(max, min) |
matches the length | isLength(5, 1) |
Options
All the validators accepts options
as the last argument.
Options include -
param | description |
---|---|
errorMessage |
Error message to show on failure |
Example
... MyReactComponentpropTypes = name: ...
TypeScript
props-validator
is not written in TypeScript, so while using it with TypeScript, you might face an error for missing type declaration file. Please add a global.d.ts
file to your project and add this content to it
declare