🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mkrause/react-form

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mkrause/react-form

React form component

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
48
700%
Maintainers
1
Weekly downloads
 
Created
Source

React form library

Basic React form library. Features a fully consumer controlled form state.

Usage

import * as ReactForm from '@mkrause/react-form';

const MyForm = () => {
  const [formBuffer, setFormBuffer] = React.useState({ name: '', email: '' });
  
  const validate = React.useCallback(({ name, email }) => {
    const errors = {};
    
    if (name.trim() === '') { errors.name = 'Required'; }
    if (email.trim() === '') { errors.email = 'Required'; }
    else if (!email.includes('@')) { errors.email = 'Invalid email'; }
    
    return errors;
  }, []);
  
  const handleSubmit = React.useCallback(() => {
    // Handle form submit
  }, []);
  
  return (
    <ReactForm.Provider
      buffer={formBuffer}
      onUpdate={setFormBuffer}
      validate={validate}
      onSubmit={handleSubmit}
    >
      {({ errors, submit }) =>
        <form onSubmit={submit}>
          <ReactForm.Field
            accessor="name"
          />
          <ReactForm.Field
            accessor="email"
          />
          
          <button type="submit">Submit</button>
        </form>
      }
    </ReactForm.Provider>
  );
};

FAQs

Package last updated on 23 May 2023

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