JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 213
  • Score
    100M100P100Q82046F
  • License MIT

A dynamic React form library which adapts to change.

Package Exports

  • fielder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fielder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Fielder logo

Fielder

A React form library which adapts to change.

build version size coverage licence docs

About

Fielder has been built from the ground up with a field-first approach to validation.

What does this mean?

  • Validation can easily be added and removed to a form
  • Only validate what the user can see (see cross form validation below)
  • No need for a large set of upfront domain knowledge

Features

⚡️Immediate validation

Synchronous validation will update state immediately in the event of a change/blur.

Fewer renders, better performance and no weird "intermediary states".

🔍 Optimized for flexibility

While Yup is supported, you're not limited to using a large Yup schema. Validation functions receive the form state as well as the field value.

(value, state) =>
  state.otherField.value === 'string'
    ? Yup.string()
        .required()
        .validateSync(value)
    : Yup.number().validateSync(value);

🤓User focused API

Users don't want to find out that the value they entered on a previous page is invalid. This is why Fielder encourages field-level validation.

If the field isn't mounted, the value won't be validated. Simple!

💁‍♂️ One way to do things

Fielder has been built with hooks since day one. There aren't any clunky APIs to learn, only useField, useForm and useFormContext.

Your data doesn't need to be coupled to your components (and likely shouldn't be), that's why Fielder doesn't include a component API.

Usage

Install Fielder

Install using your package manager of choice.

npm i fielder

Setting up a form

useForm is where you initiate your form. In order to expose the form to any child components (and subsequently useField), you'll want to expose it via context.

const myForm = useForm();

return <FielderProvider value={myForm}>{children}</FielderProvider>;

Declaring fields

useField is where you harness the power of Fielder.

const [nameProps, nameMeta] = useField({
  name: 'userName',
  validate: useCallback(
    v =>
      Yup.string()
        .required()
        .validateSync(v),
    []
  )
});

return (
  <>
    <input type="text" {...nameProps} />
    {nameMeta.touched && nameMeta.error && (
      <ErrorMsg>{nameMeta.error}</ErrorMsg>
    )}
  </>
);

There are a whole number of additional arguments which can be passed to useField which allow you to:

  • Set validation
  • Set when validation is triggered (e.g. on blur, change, etc)
  • Set initial value, error, valid and touched states
  • Set unmount behaviour

Note: Unlike other popular form libraries, Fielder allows you to change config options (such as validation) at any time.

Resources

For more info and examples, check out the official docs site.

For a deeper dive on Fielder and why it exists, check out this blog post.