@yobta/validator-react
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@yobta/validator-react

React hooks for @yobta/validator

Installation

npm i @yobta/validator
npm i @yobta/validator-react

Usage

useAsyncValidator

import { createAsyncValidator, rule } from '@yobta/validator'
import { useAsyncValidator } from '@yobta/validator-react'

const validator = createAsyncValidator(rule(async value => somePromise(value)))

Basic Usage

By default, the hook caches the validate function based on the validator provided. This means that unless the validator changes, the same validate function instance is used, optimizing performance by preventing unnecessary re-creations.

const [validate, isValidating] = useAsyncValidator(validator)

Cache Control with Dependencies

By providing a dependency list, you can control when the validate function is recreated. This is useful for optimizing performance and ensuring that the validator only updates when specific dependencies change.

const [validate, isValidating] = useAsyncValidator(validator, [dep1, dep2])

Package Sidebar

Install

npm i @yobta/validator-react

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

9.7 kB

Total Files

17

Last publish

Collaborators

  • droganov