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

zed-form

v0.0.0

Published

A radically different, yet familiar, approach to forms in React: **just let the browser do it**

Downloads

2

Readme

Zed Form

A radically different, yet familiar, approach to forms in React: just let the browser do it

zero re-renders by default

Why?

Perhaps the most frustrating part of React is dealing with forms. The standard React approach to forms is both slow and filled with boilerplate. Some libraries deal with the boilerplate by adding complexity and are still slow.

Zed Form takes a radically different, yet familiar, approach to forms: just let the browser do it.

The eventing system that is already built into the browser is incredibly fast and efficient for dealing with form inputs. React layering a bunch of unnecessary rendering and re-rendering on top of that flow really slows down pages with many form elements as everything is re-rendered on every user keystroke.

With Zed Form, every <input> is an "uncontrolled" input. Instead of forcing the input to have a certain value, and re-rendering the input on every keystroke to force it to have an updated value, Zed Form just let's the user type and keeps track of what they've typed.

On top of that, Zed Form supports all the features you've come to expect form other form libraries:

  • Schema error validation
    • Built in support for zod (but you can supply an adapter for any schema validation library
  • Setting initial values
  • "Touched" tracking, so errors by default aren't shown until the user has interacted with a particular input
  • Opt-in support for tracking a form value via React state (useful for when you need to hide or show form inputs based on a previous input value)

Install

npm i zed-form     # npm
pnpm i zed-form    # pnpm
yarn add zed-form  # yarn

Example

import {Form, useCreateForm} from 'zed-form'

function App() {
  const form = useCreateForm()
  return (
    <Form form={form}>
      <input type="text" {...form.register('foo')} />
      <input type="text" {...form.register('bar')} />
    </Form>
  )
}

Example with Schema Validation

import {Form, useCreateForm, useFormValue} from 'zed-form'
import zod from 'zod'

const schema = zod.object({
  foo: zod.enum(['foo', 'baz']),
})

function App() {
  const form = useCreateForm({
    initialValues: {foo: 'foo'},
    validationSchema: schema,
  })

  return (
    <Form form={form}>
      <TextField type="text" {...form.register('foo')} />
      <TextField type="text" {...form.register('bar')} />
    </Form>
  )
}

function TextField(props: React.ComponentProps<'input'>) {
  const error = useFormValue(`error:${props.name}`)

  return (
    <div>
      <input {...props} className="w-full" />
      {error && <p style={{color: 'red'}}>{error}</p>}
    </div>
  )
}