use-state-validate
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "use-state-validate", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Custom hook to account for state and validation off single state value", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -30,10 +30,20 @@ # use-state-validate | ||
const [`<valueWrapped>`, `<setValue>`, `<cleanValue>`] = useStateValidate(`<initialValue>`, `<rules>`) | ||
const [`<valWrap>`, `<setVal>`, `<cleanVal>`] = useStateValidate(`<initVal>`, `<rules>`) | ||
### Code | ||
``` js | ||
import useStateValidate from "use-state-validate"; | ||
const [nameV, setName, cleanName] = useStateValidate("Tim", { required: true | ||
message: { | ||
required: "A name is required" | ||
}); | ||
``` | ||
| | | | ||
| -------------- | ---- | | ||
| `valueWrapped` | An object containing the raw value and validation data, use `<valueWrapped>`.`value` to get the value | | ||
| `setValue` | Set function, that behaves like `useState`. PLEASE PASS THE RAW VALUE HERE, not a wrapper like object! | | ||
| `cleanValue` | Function to clean the dirty flag. The dirty flag defaults to false, but is set to true if `setValue` is invoked | | ||
| `initialValue` | The initial value to start with | | ||
| `valWrap` | An object containing the raw value and validation data, use `<valWrap>`.`value` to get the value | | ||
| `setVal` | Set function, that behaves like `useState`. PLEASE PASS THE RAW VALUE HERE, not a wrapper like object! | | ||
| `cleanVal` | Function to clean the dirty flag. The dirty flag defaults to false, but is set to true if `setVal` is invoked | | ||
| `initVal` | The initial value to start with | | ||
| `rules` | A mostly flat object using rules found at https://www.npmjs.com/package/validate | | ||
@@ -60,3 +70,3 @@ | ||
### Example of `valueWrapped`, showing the validation data object | ||
### Illustration of `valueWrapped`, showing the validation wrapper object | ||
``` json | ||
@@ -110,4 +120,5 @@ { | ||
### Changelog | ||
v0.0.x - Initial dev release - ASSUME UNSTABLE | ||
v0.0.x - Initial dev release - ASSUME UNSTABLE | ||
v1.0.0 - Hook has been stable in projects, bumping to initial release | ||
v1.0.1 - Readme updates - no code changes | ||
8805
122