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

react-generic-form

v0.0.5

Published

React utility for creation of generic forms

Downloads

6

Readme

What is this package?

This package is a nice little utility designed to provide an excellent way to generalize forms data and their fundamental interactions.

Features:

  1. Form&Input data generalization
  2. Forms nesting inside other forms
  3. Configurable form validation rules stored inside props instead of being hardcoded.
  4. Overall code simplification because most of the generic steps hidden under the hood of base components

Why is it necessary?

Quite a while ago I was leading development of an ambitious web project which used React in the front end. I quickly found that the creation of the forms is way too repetitive. Most of the time developers were doing the same thing. They were manually creating the form state and data structure. Besides, they were trying to implement complex behavior using callbacks and chaotically placed state fields. Therefore I made a small utility which simplified their lives a lot. So now I want to share it with the world. So, this is just DRY utility. It also helps a lot with a generalization of a data structure. I guess I shouldn't explain why all of this is important.

Contents:

  1. Component class - it extends basic react component functionality by adding two static methods which allow updating of defaultProps and propTypes static properties.
  2. Input class - extends Component class. Its purpose is the generalization of form inputs to enable the next class, Form, to use these fields. In two words, this class is an "interface" which wraps your custom inputs.
  3. Form class - extends Component class. It is the main class. I combine inputs and other forms(as nested) into a single organized entity.
  4. createRule function. It generates a function which Form class uses to verify input values. It's useful because it gives an ability to change verification rules from props by changing an array of rules for a particular field. Each rule function has two methods attached to it which set message builder function and rule parameters.

General workflow/Tutorial:

  1. Wrap custom inputs in extensions of BaseInput component. Example
  2. Create reusable field validation rules using createRule function.Example
  3. Create a form extending Form component, add all fields and rules you need.Example
  4. Nest some forms just like regular inputsj+ inside other form if you need so.Example

Note:

This is fully functional demo which you can run using docker & docker-compose. It's a linux setup which uses make for commands shortcuts.