All Projects → sinclairnick → react-plough

sinclairnick / react-plough

Licence: other
A library to help tend your react form fields

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-plough

Swarmpit
Lightweight mobile-friendly Docker Swarm management UI
Stars: ✭ 2,255 (+7174.19%)
Mutual labels:  management
Akka Management
Akka Management is a suite of tools for operating Akka Clusters.
Stars: ✭ 218 (+603.23%)
Mutual labels:  management
Publicleech
can be found on Telegram as https://telegram.dog/PublicLeechGroup
Stars: ✭ 236 (+661.29%)
Mutual labels:  management
Cfpmp
Cloudflare Partner Management Panel
Stars: ✭ 194 (+525.81%)
Mutual labels:  management
Farm
Zerocrat Core Engine
Stars: ✭ 207 (+567.74%)
Mutual labels:  management
Storaji
📒 The light/responsive inventory management system available on Windows, macOS and Linux.
Stars: ✭ 222 (+616.13%)
Mutual labels:  management
Happypanda
A cross platform manga/doujinshi manager with namespace & tag support
Stars: ✭ 161 (+419.35%)
Mutual labels:  management
P5 Manager
A p5js template builder & sketches manager. Built for p5js enthusiasts.
Stars: ✭ 251 (+709.68%)
Mutual labels:  management
Kiali
Kiali project, observability for the Istio service mesh
Stars: ✭ 2,687 (+8567.74%)
Mutual labels:  management
Pallas
Curator is to Zookeeper what Pallas is to Elasticsearch
Stars: ✭ 230 (+641.94%)
Mutual labels:  management
Knative Lambda Runtime
Running AWS Lambda Functions on Knative/Kubernetes Clusters
Stars: ✭ 201 (+548.39%)
Mutual labels:  management
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (+558.06%)
Mutual labels:  management
Masterplan
MasterPlan is a project management software / visual idea board software. It attempts to be easy to use, lightweight, and fun.
Stars: ✭ 221 (+612.9%)
Mutual labels:  management
Poshkeepass
PowerShell module for KeePass
Stars: ✭ 177 (+470.97%)
Mutual labels:  management
Ekylibre
Farm management Information System - Connecting farms to the world
Stars: ✭ 246 (+693.55%)
Mutual labels:  management
Atutor
NO LONGER USER LEVEL SUPPORTED. CONTRIBUTING DEVELOPERS INTERESTED IN MAINTAINING ATUTOR, SHOULD REQUEST COLLABORATOR ACCESS. : ATutor is an Open Source Web-based Learning Management System (LMS) used to develop and deliver online courses. Administrators can install or update ATutor in minutes, develop custom themes to give ATutor a new look, and easily extend its functionality with feature modules. Educators can quickly assemble, package, and redistribute standardized Web-based instructional content, easily import prepackaged content, and conduct their courses online. Students learn in an accessible, adaptive, social learning environment.
Stars: ✭ 166 (+435.48%)
Mutual labels:  management
Temboard
PostgreSQL Remote Control
Stars: ✭ 218 (+603.23%)
Mutual labels:  management
Nvm Windows
A node.js version management utility for Windows. Ironically written in Go.
Stars: ✭ 18,587 (+59858.06%)
Mutual labels:  management
Xtuple
This repository contains the source code for the database schema for the PostBooks edition of xTuple ERP and xTuple's REST API server. The REST API server is written in JavaScript running on Node.js. The database schema for PostBooks runs on a PostgreSQL database server.
Stars: ✭ 247 (+696.77%)
Mutual labels:  management
Open Product Management
A curated list of product management advice from frameworks, interviews, experts, resources, books, products, career preps, and much more. The list is divided into cores such as product management, resources, interviews, case Studies, sample products/projects, communities, open source projects, free and paid services. There is no pre-established order of items in each category, the order is for contribution. If you want to contribute, please read the guide. Feel free to add products or links to help other product managers.
Stars: ✭ 2,902 (+9261.29%)
Mutual labels:  management

🚨 This project has been archived. I recommend using React Hook Form instead.

React Plough 👨‍🌾

A library to help tend your react fields

yarn add react-plough
npm i react-plough

react-plough is yet another react form library. It prioritises developer experience and aims to reduce user error by providing strongly typed and performant interfaces for react form fields. Unlike existing form libraries, plough does not use react context and does not require any manual type annotation. In other words, it is lightweight and hard to screw up.

plough is 3 to 700x faster than Formik *(see bottom)

Play with the Formik comparison

Check out the Docs


Basic Usage

Plough views fields as the atomic unit of user-input and uses a familiar API, but is designed as a library, not a framework. As such, plough fits around your code, instead of fitting your code around itself. A basic example looks like:

import { useTextField } from "react-plough";

const LoginForm = () => {
  const [nameProps, name] = useTextField({
    validate: (name) =>
      name.value.length === 0 ? "Name must be provided" : undefined,
  });

  const [passwordProps, password] = useTextField({
    validate: (password) =>
      password.value.length === 0 ? "Password is required" : undefined,
  });

  const handleSubmit = () => {
    alert(`${name.value} ${password.value}`);
  };

  return (
    <div>
      <input {...nameProps} />
      <input {...passwordProps} />
      <button onClick={handleSubmit}></button>
    </div>
  );
};

The fields are not dependent on each other and don't use any react context. This means it causes the minimum amount of re-renders, and gradual adoption is simple. In the basic case, plough acts like a glorified useState with some input-specific helpers.

However, forms often exist across several layers of the DOM tree, have lists of fields and have more complicated requirements. As such, opt-in utilities exist to enable complicated use-cases too.


A more realistic example

Bear in mind that all of the below is strongly typed -- no guessing or type annotation required

const form = createForm({
  name: "",
  age: "8", // HTML <input/> numbers are still strings
  friendNames: [""],
});

export const ProfileForm = () => {
  const [nameProps] = form.useName();
  const [ageProps] = form.useAge({
    validate: (val) => (Number(val) < 18 ? "Must be over 18" : undefined),
  });

  return (
    <div>
      <input {...nameProps} />
      <input {...ageProps} type="number" />
      <FriendForm />
    </div>
  );
};

// <name> or <age> won't trigger updates here
export const FriendForm = () => {
  const [friends, friendsActions] = form.useFriendNames();

  const handleSave = () => {
    const [values, meta] = form.collect(); // Includes <name> and <age>
    if (!meta.isDirty) {
      throw new Error("Please add some friends");
    }
    alert(values);
  };

  return (
    <div>
      {friends.map((friend, i) => (
        <div>
          <input {...friend.props} />
          <button onClick={friend.actions.remove}>Delete</button>
        </div>
      ))}
      <button onClick={friendsActions.addItem}>Add friend</button>
      <button onClick={handleSave}>Save</button>
    </div>
  );
};

Check out the other functions exported from plough to see other helpers

Notes on the Formik Comparison and Performance

In most cases, performance won't be that important. But when forms do have performance issues, these issues are often hard to fix and very problematic

While this describes Formik, most of the points here apply to other existing form libraries, as they tend to use the same underlying approach

The Formik comparison evaluated various things like number of sibling component re-renders, time to re-render and time to pull out values upon submission. To do this, many inputs (from 1 to 100,000) were created. Of course, no one will likely ever need 100,000 inputs, but this case emulates the behaviour of, say, having expensive calculations run in only a few components.

Sibling re-renders

Formik causes a re-render of sibling components (within the <Formik/> component) when any field in that component changes. Conversely, plough does not do this. So, in effect Formik renders sibling components potentially infinitely more than plough.

Extracting form values for submission

The disparity between Formik and plough here is surprising. With 100,000 inputs, Formik takes 7000ms to retrieve the values, whereas plough only takes 10!

Input-Re-render delay

Across every scale of evaluation, plough outperformed Formik. While smaller trials showed a difference that is negligible in practice, the larger trials showed the fundamental difference in performance between the two libraries.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].