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

use-formio

v0.0.18

Published

![Use formio logo](./example/assets/useformio-horizontal.svg)

Downloads

398

Readme

use-formio

Use formio logo

Online interactive documentation is availabe on http://use-formio.svehlik.eu

use-formio is React form library which help you to build forms with just a few lines of code and without extra layer of abstraction.

use-formio is micro library with 0 dependencies.

Each of your application deserves custom UI solution so it does not make sense to use separate library to handle form UIs.

In useFormio you just define custom business model and don't waste a time with boilerplate around.

installation

npm install use-formio

Examples

you can find more examples on http://use-formio.svehlik.eu

import * as React from "react";
import { useFormio } from "useFormio";

const delay = (time: number) => new Promise(res => setTimeout(res, time));
const maxLen3 = (value: string) => value.length <= 3

export const Example = () => {
  const form = useFormio(
    {
      firstName: "",
      lastName: ""
    },
    {
      firstName: {
        validator: value => [
          value.length > 10 ? "max len is 10" : undefined,
          value.length < 4 ? "min len is 4" : undefined
        ]
      },
      lastName: {
        validator: async (value, state) => {
          if (state.age > 20) {
            await delay(1000);
            return Math.random() > 0.5 ? "Random error thrower" : undefined;
          }
          return undefined
        }
      }
      age: {
        validator: value => [
          value === "" ? "input cannot be empty" : undefined,
          parseInt(value) < 18 ? "age has to be > 18" : undefined
        ],
        shouldChangeValue: maxLen3
      },
      isVerified: {
        validator: value => (value === false ? "value has to be checked" : undefined)
      }
    }
  );
  const f = form.fields;

  return (
    <form
      onSubmit={async e => {
        e.preventDefault();
        const [isValid, errors] = await form.validate();
        if (isValid) {
          alert("Successfully submitted");
        } else {
          console.error(errors)
        }
      }}
    >
      <label>First name</label>
      <input
        type="text"
        onChange={e => f.firstName.set(e.target.value)}
        value={f.firstName.value}
        onBlur={() => f.firstName.validate()}
        disabled={f.firstName.isValidating}
      />
      <div className="input-error">{f.firstName.errors.join(",")}</div>

      <label>Last name</label>
      <input
        type="text"
        onChange={e => f.lastName.set(e.target.value)}
        value={f.lastName.value}
        onBlur={() => f.lastName.validate()}
        disabled={f.lastName.isValidating}
      />
      <div className="input-error">{f.lastName.errors.join(",")}</div>

      <label>Age</label>
      <input type="number" onChange={e => f.age.set(e.target.value)} value={f.age.value} />

      <div className="input-error">{f.age.errors.join(",")}</div>

      <label>Terms of conditions</label>
      <input
        type="checkbox"
        checked={f.isVerified.value}
        onChange={e => f.isVerified.set(e.target.checked)}
      />

      <button type="submit" disabled={form.isValidating}>
        submit
      </button>
    </form>
  );
};