New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rc-use-form

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-use-form

manage form state use React Hooks

  • 0.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

rc-use-form

manage form state use React Hooks. https://ariesjia.github.io/react-use-form/

NPM Build Status

Install

// use yarn
yarn add rc-use-form
// use npm
npm install rc-use-form

Demo

simple

import useForm from 'rc-use-form';

const Demo = () => {
  const [form, field]  = useForm({
    name: '',
    password: ''
  })
  
  const handleSubmit = (event) => {
    event.preventDefault()
    console.log(form.value)
  }
  
  return (
    <div>
      <form onSubmit={handleSubmit}>
        <div>
          <label>username</label>
          <input type="text" {...field("name")}/>
        </div>
        <div>
          <label>password</label>
          <input type="password" {...field("password")} />
        </div>
        <button type='submit'>submit</button>
      </form>
    </div>
  )
}

validate

import useForm from 'rc-use-form';

const Demo = () => {
  const [form, field]  = useForm({
    name: '',
    password: ''
  })
  
  const handleSubmit = (event) => {
    event.preventDefault()
    form.validate((errors) => {
      if(!errors) {
        console.log(form.value)
        alert('submit')
      }
    })
  }
  
  return (
    <div>
      <form onSubmit={handleSubmit}>
        <div>
          <label>username</label>
          <input type="text" {...field("name", {
            rules: [{type: "string", required: true}]
          })}
          />
          {
            form.errors.name && <div>
                {form.errors.name[0].message}
            </div>
          }
        </div>
        <div>
          <label>password</label>
          <input type="password" {...field("password", {
            rules: [{type: "string", required: true}]
          })}
          />
          {
            form.errors.password && <div>
                {form.errors.password[0].message}
            </div>
          }
        </div>
        <button type='submit'>submit</button>
      </form>
    </div>
  )
}

form

  • value: The form data
  • touched: The field had been changed by user
  • errors: The form validate errors
  • validate: The form validate function
  • getValue: The form getValue function, always return current value

field

field(name, [options])
  • name: The field field (required).
Options

Keywords

FAQs

Package last updated on 27 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc