1.1.2 • Published 1 year ago

@fun-land/react-validation v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

A set of helpers to make using @fun-land/validation with React pleasant.

Usage

See @fun-land/validation for examples.

API

validateAndAct

<State>(
  state: FunState<State>,
  validator: Validator<State>,
  action: (state: State) => unknown
) => void

Run validator on state an do an action if everything is good.

Example:

validateAndAct(formState, formValidator, postForm)

TextInputState

interface TextInputState {
  value: string
  errorMessage: string
}

Interface for input[type=text] and textarea element state.

initTextInputState

;(value: string) => TextInputState

Helper to create a TextInputState instance

textInputValidator

(
  testFunction: (value: string) => boolean,
  errorTemplate: string | ((value: string) => string)
) => Validator<TextInputState>

Creates a Validator<TextInputState> to work with text inputs and text areas.