Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@evandrolg/react-form-helper

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@evandrolg/react-form-helper

Simple way to build forms in React.

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ReactFormHelper

Simple way to build forms in React.

Build Status license

Installation

To install ReactFormHelper, execute:

  $ npm install @evandrolg/react-form-helper

Features

  • Powerful and flexible hook to validate forms
  • Helper validation functions such as email and password

Docs

Quickstart

import React from 'react';
import PropTypes from 'prop-types';
import {
  useForm,
  isEmailValid,
  isPasswordValid,
} from '@evandrolg/react-form-helper';

import { FormGroup, Label, SubmitButton, Input, FieldError } from './Form';

const validation = ({ email, username, password }) => {
  return {
    ...(!isEmailValid(email) && { email: 'E-mail is not valid' }),
    ...(!username && { username: 'Username is required' }),
    ...(!isPasswordValid(password) && { password: 'Password is not valid' }),
  };
};

const submit = (data) => {
  console.log(data);
};

const Signup = () => {
  const [getInputValue, handleChange, handleSubmit, isValid, errors] = useForm(
    validation,
    submit,
  );

  return (
    <form onSubmit={handleSubmit}>
      <FormGroup>
        <Label htmlFor="email">*E-mail</Label>
        <Input
          type="text"
          id="email"
          value={getInputValue('email')}
          onChange={handleChange}
        />
        {errors.email && <FieldError>{errors.email}</FieldError>}
      </FormGroup>

      <FormGroup>
        <Label htmlFor="username">*Username</Label>
        <Input
          type="text"
          id="username"
          value={getInputValue('username')}
          onChange={handleChange}
        />
        {errors.username && <FieldError>{errors.username}</FieldError>}
      </FormGroup>

      <FormGroup>
        <Label htmlFor="password">*Password</Label>
        <Input
          type="password"
          id="password"
          value={getInputValue('password')}
          onChange={handleChange}
        />
        {errors.password && <FieldError>{errors.password}</FieldError>}
      </FormGroup>

      <SubmitButton value="Sign up" disabled={!isValid} />
    </form>
  );
};

FAQs

Package last updated on 05 Mar 2020

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