React State Validation
React State Validation uses the propTypes validation pattern to validate states.
Usage
The stateValidation
method can be used a decorator.
const stateValidations = { if !/matchme/ return 'Validation failed!'; } @stateValidation { super thisstate = customState: '' } { // the stateValidation method will set the errors key will the current state errors const errors = thisstate // the key of the state will be the same key in the errors object const customState = errors // if there is errors it will be an array of strings // eg. ['Validation failed!'] //... } AppstateValidations = stateValidations
or if your not using decorators you can just wrap the component with the stateValidation method.