@de-formed/react-validations
Advanced tools
+1
-1
| { | ||
| "name": "@de-formed/react-validations", | ||
| "version": "4.0.0", | ||
| "version": "4.0.1", | ||
| "description": "Modular, Function-driven Validations", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
+30
-0
@@ -76,2 +76,4 @@ <p align="center"> | ||
| --- | ||
| ### Step 2: Use the hook anywhere. | ||
@@ -130,2 +132,30 @@ | ||
| ## Validation Schema | ||
| The validation schema is on object that defines a list of validation rules for | ||
| any given key. Each validation rule consists of the `error` to display to a | ||
| user and a function that returns true or false. Error messages can be passed a | ||
| function to generate dynamic error messages depending on the state of the data. | ||
| Keys that match the keys of an object will be automatically detected when using | ||
| `validateAll`. | ||
| ```ts | ||
| { | ||
| email: [ | ||
| { | ||
| error: 'Email is required.', | ||
| validation: ({ email }) => email.trim().length > 0, | ||
| }, | ||
| { | ||
| error: ({ email }) => `${email} must be a valid email.`, | ||
| validation: ({ email, name }) => | ||
| name === 'bob ross' ? email === 'bob.ross@gmail.com' : true | ||
| }, | ||
| ], | ||
| } | ||
| ``` | ||
| --- | ||
| ## Getting Started | ||
@@ -132,0 +162,0 @@ |
37903
2.05%174
20.83%