|
4 | 4 | <img src="https://img.shields.io/npm/v/@tswaters/react-form-validation" alt="npm version"> |
5 | 5 | </a> |
6 | 6 | <a href="https://travis-ci.org/tswaters/react-form-validation/"> |
7 | | - <img src="https://img.shields.io/travis/tswaters/react-form-validation" alt="npm version"> |
| 7 | + <img src="https://img.shields.io/travis/tswaters/react-form-validation" alt="build status"> |
8 | 8 | </a> |
9 | 9 | <a href="https://coveralls.io/github/tswaters/react-form-validation"> |
10 | | - <img src="https://img.shields.io/coveralls/github/tswaters/react-form-validation" alt="npm version"> |
| 10 | + <img src="https://img.shields.io/coveralls/github/tswaters/react-form-validation" alt="coverage"> |
11 | 11 | </a> |
12 | 12 | <a href="https://github.com/tswaters/react-form-validation/blob/master/LICENSE"> |
13 | | - <img src="https://img.shields.io/npm/l/@tswaters/react-form-validation" alt="npm version"> |
| 13 | + <img src="https://img.shields.io/npm/l/@tswaters/react-form-validation" alt="license (MIT)"> |
14 | 14 | </a> |
15 | 15 |
|
16 | 16 | The goal of this library is to implement the [Constraint Validation API](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-constraint-validation-api) in React while not getting in your way to do it. |
@@ -42,7 +42,7 @@ These are wrappers around `<form/>` and `<input/select/textarea>` elements. Any |
42 | 42 |
|
43 | 43 | `Input` elements must be children of a `Form` element. Under the covers, this library uses context to keep track of all fields on the form and will validate all of them if the form is submitted. |
44 | 44 |
|
45 | | -A `Validator` component is also provided which attempts to make using the api a bit easier. This is a container element that uses a render prop which is called with `({ error, valid, invalid, validated })`. This routine recursively traverses any provided props to replace `input/select/textarea` elements with the exports from this library, so it will duplicate any work on the tree that react may have done on that JSX tree up to that point. |
| 45 | +A `Validator` component is also provided which attempts to make using the api a bit easier. This is a container element that uses a render prop which is called with `({ error, valid, invalid, validated })`. This routine recursively traverses any provided props to replace `input/select/textarea` elements with the exports from this library, so it will duplicate any work already done up to that point. |
46 | 46 |
|
47 | 47 | ## api |
48 | 48 |
|
@@ -274,6 +274,12 @@ const ErrorDisplay = error => { |
274 | 274 |
|
275 | 275 | For custom error messages, `error.message` will be whatever you returned or threw back and the code will be `customError` |
276 | 276 |
|
| 277 | +## Thoughts on Performance |
| 278 | +
|
| 279 | +- make sure the tree passed via `<Validator />` is pretty simple. Validator recursively traverses the tree and replaces html inputs with exports from this library. |
| 280 | +
|
| 281 | +- validation functions should be memoized lest any change invoke a re-render (wrap functions with `useCallback`, or an array of functions with `memo`) |
| 282 | +
|
277 | 283 | ## limitations / bugs |
278 | 284 |
|
279 | 285 | - only the first error for a given input element will be returned |
|
0 commit comments