2.0.3 • Published 1 year ago

reaction-formula v2.0.3

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

Install

Install the package via npm or use the command npm i reaction-formula

Usage

import { useReactionFormula, ReactionFormula } from 'reaction-formula'

//validation using a hook
export const ValidationUsingHook = () => {
  const [data, setData, event, eventHandler, validator] = useReactionFormula({
    email: '',
  })
  return (
    <div>
      {event.isFocus && !validator.isEmail(data.email) && 'error'}
      <input
        value={data.email}
        onChange={(e) => setData({ ...data, email: e.target.value })}
        onBlur={eventHandler.onBlur}
        onFocus={eventHandler.onFocus}
      />
    </div>
  )
}

//validation using a component
export const ValidationUsingComponent = () => {
  return (
    <div>
      <ReactionFormula
        data={{ email: '' }}
        component={({ data, setData, event, eventHandler, validator }) => {
          return (
            <>
              {event.isFocus && !validator.isEmail(data.email) && 'error'}
              <input
                value={data.email}
                onChange={(e) => setData({ ...data, email: e.target.value })}
                onBlur={eventHandler.onBlur}
                onFocus={eventHandler.onFocus}
              />
            </>
          )
        }}
      />
    </div>
  )
}

export const App = () => {
  return (
    <>
      <ValidationUsingHook />
      <br />
      <ValidationUsingHook />
    </>
  )
}

Check out the validator library, as it is used for data validation.

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago