@fun-land/react-validation
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@fun-land/react-validation

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.

Package Sidebar

Install

npm i @fun-land/react-validation

Weekly Downloads

1

Version

2.0.0

License

ISC

Unpacked Size

94.1 kB

Total Files

25

Last publish

Collaborators

  • jethrolarson