Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/react-form-state

Package Overview
Dependencies
Maintainers
0
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/react-form-state

Manage React forms tersely and type-safely with no magic

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
855
decreased by-19.26%
Maintainers
0
Weekly downloads
 
Created
Source

@shopify/react-form-state

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

Manage React forms tersely and type-safely with no magic.

This library is now superseded by @shopify/react-form as it allows you to write the preferred, functional, and hooks-driven React components over class-based ones.

Installation

yarn add @shopify/react-form-state

Usage

<FormState />

The default component exported by this library is <FormState />.

import FormState from '@shopify/react-form-state';
// Fields here refers to the inferred type of your initialValues object
interface Props<Fields> {
  initialValues: Fields;
  validators?: Partial<ValidatorDictionary<Fields>>;
  onSubmit?: SubmitHandler<Fields>;
  validateOnSubmit?: boolean;
  children(form: FormDetails<Fields>): React.ReactNode;
}

Its only mandatory props are initialValues and children. The initialValues prop is used to infer all the types for the rest of the component, and to generate handlers and field state objects. The children prop expects a function of the current state of the form, which is represented by a FormDetails object.

<FormState initialValues={myInitialValues}>
  {({fields, dirty, valid, submitting, errors, reset, submit}) => {
    return /* some cool ui */;
  }}
</FormState>

For detailed explanations of how to use <FormState /> check out the guide.

validators

The library also makes a number of validation factory functions available out of the box that should help with common use cases, as well as some tools to make building reusable custom validators easy.

import {validate, validators} from '@shopify/react-form-state';

For detailed explanations of the validation utilities, check out the validation docs.

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc