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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@surya_tomar/react-super-forms

v1.0.3

Published

A powerful form handling library for React.

Downloads

1

Readme

React Super Forms

React Super Forms is a powerful library designed to simplify form handling and validation in React applications.

Installation

Install the library via npm:

npm install @surya_tomar/react-super-forms

Usage

Here's a basic example to get you started:

import React from 'react';
import { Form, FormField, useForm, useField } from '@surya_tomar/react-super-forms';

const MyForm = () => {
  const formState = useForm(
    { name: '' }, 
    { name: { required: true, minLength: 3 } }
  );
  const nameField = useField('name', formState);

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

  return (
    <Form onSubmit={handleSubmit}>
      <FormField {...nameField} label="Name" />
      <button type="submit">Submit</button>
    </Form>
  );
};

export default MyForm;

Components

Form

Wrapper component that handles form submission.

Props:

  • onSubmit (function): Function called when the form is submitted.
<Form onSubmit={handleSubmit}>{children}</Form>

FormField

Represents an individual form field.

Props:

  • name (string): Name of the form field.
  • label (string): Label for the form field.
  • type (string): Type of the form field input (default: 'text').
  • value (string): Current value of the form field.
  • onChange (function): Function called when the form field value changes.
  • error (string): Error message for the form field.
<FormField 
  name="name" 
  label="Name" 
  type="text" 
  value={value} 
  onChange={onChange} 
  error={error} 
/>

Hooks

useForm

Custom hook that manages form state and validation.

Arguments:

  • initialState (object): Initial state of the form.
  • validationSchema (object): Validation rules for form fields.

Returns:

  • values (object): Current form values.
  • errors (object): Current form errors.
  • handleChange (function): Function called when a form field value changes.
const formState = useForm(initialState, validationSchema);

useField

Custom hook that provides props for a form field.

Arguments:

  • name (string): Name of the form field.
  • formState (object): Form state returned by useForm.

Returns:

  • name (string): Name of the form field.
  • value (string): Current value of the form field.
  • onChange (function): Function called when the form field value changes.
  • error (string): Error message for the form field.
const fieldProps = useField(name, formState);

Utilities

Validation

Includes a utility for common validation rules.

Supported Rules:

  • required (boolean): Whether the field is required.
  • minLength (number): Minimum length of the field value.
const validationSchema = {
  name: { required: true, minLength: 3 },
};

Features

  • Simple API for managing forms and form fields.
  • Built-in validation rules.
  • Easy integration with custom components and styles.
  • Optimized for performance with minimal re-renders.

Contributing

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -am 'Add a new feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Thanks to all contributors and users for their support and feedback.