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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@danny-ui/react-form

v0.1.4

Published

This React Form component helps you:

Downloads

13

Readme

Introduction

This React Form component helps you:

  • Maintain Form state
  • Debounced field validation
  • Validate field asynchronously
  • Handle form submission
  • prevent multiple form submission
  • Reduce field re-render by detecting if field value changes

Installation

Install lodash (">=4.17.15") and rxjs (">=6.5.x) if you don't have it.

npm install --save lodash rxjs

Install react-form

npm install --save @danny-ui/react-form

Usage

import { Form, useField } from '@danny-ui/react-form';

function TextField({
  name = '',
  label = '',
  required = false,
  defaultValue = '',
  validate,
  type = 'text',
}) {
  const { value, onChange, meta } = useField({
    name,
    displayName: label,
    validate,
    required,
    defaultValue,
  });

  return (
    <div>
      <label>{label}</label>
      <input
        onChange={(ev) => onChange(ev.target.value)}
        value={value}
        type={type}
      />
    </div>
  );
}

<Form
  onSubmit={async (value) => {
    window.alert(JSON.stringify(value));
  }}
>
  <TextField
    required
    validate={async (value) => {
      await new Promise((res) => setTimeout(res, 100));
      const isEmailValid = /^[^@]+@[^@]+\.[^@]+$/.test(value);
      return !isEmailValid && new Error('Invalid Email Address');
    }}
    label="Email Address"
    name="email"
  />
  <TextField required name="password" label="Password" type="password" />
  <button type="submit">Submit</button>
</Form>;

Examples

Please check examples here.

API

Form Properties

| Name | Type | Description | | -------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children* | node | The content of the form, normally Field component with useField hook. | | onSubmit* | func | Callback fired when the form is submitted. Signature: function(value: object, meta: object) => Promise Return value of onSubmit function will be passed to success callback | | success | func | Callback fired when onSubmit function is resolved. Signature: function(submitReturn: any, value: object) => Promise | | failed | func | Callback fired when onSubmit function is rejected. Signature: function(errors: [Error], value: object) => void | | beforeSubmit | func | Callback fired before onSubmit function is called. Signature: function(values: object, meta: object) => Promise | | extendFormMeta | func | Callback fired after an action updated form state. The return object will be merged into form meta Signature: function(state: object) => object | | className | string | css apply to form |

useField Properties

| Name | Type | Description | | --------------------- | ------ | ----------------------------------------------------------------------------------------------------------- | | name* | string | key to lookup form value | | defaultValue* | any | default field value | | required | bool | if true, field onChange action and form onSubmit will check if this field value is empty | | displayName | string | use with required props, and display the error message as `${displayName} is required` | | destroyValueOnUnmount | bool | When field unmount, determine whether to destroy the field value or not | | validate | func | Callback fired when field value changed. Signature: function(value: object) => Promise |

FormValues Properties

| Name | Type | Description | | ---------- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children* | func | It exposes the formValue and it is normally used for linked fields. Signature: function(value: object) => node | | filter | func | It is used to improve performance. You can use it to control if the children function should be called. Similar to react shouldComponentUpdate life circle Signature: function(value: object) => bool |

FieldOnChange Properties

| Name | Type | Description | | ---------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children* | func | It can detect field onChange action and you can use it to update associated fields. Signature: function(props: object) => void props: an object type of {action, formValues, updateFormValues: (changes: {path: string, value: any}[]) => void} |

FormMeta Properties

| Name | Type | Description | | ---------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children* | func | It exposes the form meta and provides the current form state. It is normally used for buttons. Signature: function(formMeta: object) => node |

License

MIT License.