npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-simple-hooks-forms

v0.2.13

Published

Performatic forms for React/React Native using hooks api. Yes we're running out of names for React Forms with hooks.

Readme

React Simple Hooks Forms

Performatic forms for React/React Native using hooks api. Yes we're running out of names for React Forms with hooks.

Typescript typings available.

Installation

yarn add react-simple-hooks-forms

or

npm i react-simple-hooks-forms

Basic Usage

Build your inputs: (works with React and React Native)

import React from 'react'
import { useFormInput } from 'react-simple-hooks-forms'

export const TextFormField = (props) => {
    const { value, setValue } = useFormInput(props)
    const onChange = (e) => setValue(e.target.value)
    
    return <input
      name={props.name}
      value={value}
      onChange={onChange}
    />
}

Wrap your fields with the Form component:

import React from 'react'
import { useForm } from 'react-simple-hooks-forms'
import { TextFormField } from './TextFormField'

const validator = (values) => {
  const errors = {}
  if (!values.name) {
    errors.name = 'Name is required'
  }
  return errors
}

const initialValues = { name: 'John' }

const App = () => {
  const { Form, submit, reset } = useForm({ initialValues, validator })
  return <Form>
    <TextFormField name={'name'} />
    <TextFormField name={'email'} />
    <button onClick={submit}>
      Submit
    </button>
    <button onClick={reset}>
      Reset
    </button> 
  </Form>
}

Listening to Field Values

In many cases you may need to do something based on the value of a field, like changing the value of another field for instance. For this you may use the hook useFormFieldValue, and it works in any component that is wrapped with the Form context.

import { useForm, useFormFieldValue } from 'react-simple-hooks-forms'

const getPasswordStrength = (password) => {
  if (password.length >= 20) {
    return 'very strong'
  } else if (password.length >= 10) {
    return 'strong'
  } else if (password.length >= 6) {
    return 'adequate'
  }
  return 'week'
}

const PasswordStrength = () => {
  const { value: passwordValue } = useFormFieldValue('password')
  
  return <div>{`This password is ${getPasswordStrength(passwordValue)}`}</div>
}

export default () => {
  const { Form } = useForm()
  
  return <Form>
    <TextFormField name={'password'} />
    <PasswordStrength />
  </Form>
}

Although not recommended in most cases because of performance issues, you may use it outside the Form context by providing a name to both your useForm and your useFormFieldValue hooks:

const formName = 'LoginForm'

export default () => {
  const { Form } = useForm({ formName })
  const { value: passwordValue } = useFormFieldValue('password', { formName })
  return <Form>
    <TextFormField name={'password'} />
    <div>{`This password is ${getPasswordStrength(passwordValue)}`}</div>
  </Form>
}

You may use this hook to set the values of fields as well. In the next example we fill a username field based on the name field. You can pass a configuration like { setterOnly: true } if you do not wish to listen to the value and simply have a setter for it.

const formName = 'SignUpForm'

export default () => {
  const { Form } = useForm({ formName })
  const { value: fullNameValue } = useFormFieldValue('fullName', { formName })
  const { set: setUsername } = useFormFieldValue('username', { formName, setterOnly: true })
  
  useEffect(() => {
     setUsername(nameValue.trim().toLowerCase())
  }, [nameValue])
  
  return <Form>
    <TextFormField name={'fullName'} />
    <TextFormField name={'username'} />
  </Form>
}

Validation

This lib provides form and field-level validation. To use form-level validation simply pass a validator function to the useForm hook. This function receives a FormValues object and should return an object containing the error messages. You might want to use a third party library to handle this, like ValidateJs.

const validator = (values) => {
  const errors = {}
  if (!values.name) {
    errors.name = 'Name is required'
  } else if (values.name.length < 2) {
    errors.name = 'Name is too short'
  }
  return errors
}

export default () => {
  const { Form, submit } = useForm({ validator })
  return <Form>
    <TextFormField name={'name'} />
    <button onClick={submit}>
      Submit
     </button>
  </Form>
}

You can use field-level validation by passing a validator prop to your wrapped input component. This will by default validate the field on every input change.

const passwordValidator = (password) => {
  if (password.length < 6) {
    return 'Password is too short'
  }
}

export default () => {
  const { Form } = useForm()
  return <Form>
    <TextFormField 
      name={'password'} 
      validator={passwordValidator} 
     />
  </Form>
}

You can choose to validate on the field's onBlur:

const TextFormField = (props) => {
    const { value, setValue } = useFormInput(props)
    const onChange = (e) => setValue(e.target.value)
    return <input
      name={props.name}
      value={value}
      onChange={onChange}
    />
}

export default () => {
  const { Form } = useForm()
  return <Form>
    <TextFormField 
      name={'password'} 
      validate={passwordValidator}
      validationOptions={{
        trigger: ValidationOptions.BLUR,
      }}
     />
  </Form>
}

TBD

Async Validation

Documentation on Api Reference