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

@irvingjs/forms

v6.16.0

Published

Form components and submission functionality for Irving

Downloads

5,767

Readme

Irving Forms

This package contains utilities, logic, and configuration for helping users create forms that submit to an external endpoint. Under the hood, this package uses react-hook-form to manage client-side form state and validation. This package consists of two peice you will need in order to set up connected form functionality:

  • irving.config.js - a configuration preset for this package containing the sagas, reducers, and default state necessary to handle form state and data.
  • useConnectedForm.js - a hook for managing form state, integrating with the react-hook-form API, and triggering form submissions.

Configuration

Configuration for submitting forms and managing their state in redux is a simple process. Import the irving config from the forms package, and add the imported config to the packages section of your project's config. Example:

import formsConfig from '@irvingjs/forms';

export default {
    packages: [
        formsConfig,
    ],
};

Integrating useConnectedForm

This hook will help you create a form that will submit to an external endpoint and report its status to Irving's internal, global redux data store.

The useConnectedForm hook expects two parameters when called:

  • formEndpoint - a form endpoint in one of three possible formats:
    • A string (containing no forward slashes). This will submit your form to an endpoint nested unter a form endpoint path. Example: if your endpoint root is https://my-domain.com/api and you provide myForm as the first parameter to useConnectedForm, it'll submit the form to https://my-domain.com/api/form/myForm.
    • A path. This will submit your form to an endpoint at your api root. Example: if your endpoint root is https://my-domain.com/api and you provide lorem/ipsum/myForm as the first parameter to useConnectedForm, it'll submit the form to https://my-domain.com/api/lorem/ipsum/myForm.
    • A fully-qualified URL. This will submit your for to the URL provided, as-is. Example: if you provide https://another-endpoint.com/api as the first parameter to useConnectedForm, it'll submit the frm to https://another-endpoint.com/api.
  • useFormOpts - options to pass to the underlying instance of react-hook-form's useForm hook. See the react-hook-form documentation for all available options.

useConnectedForm will return an object containing data you can use in any way you choose:

  • onSubmit - a function you can supply to a form onSubmit event handler to validate (if configured) and submit your form to the provided endpoint.
  • formApi - the react-hook-form api, returned directly from the underlying instance of the useForm hook. See the react-hook-form documentation for the full API.
  • formState - global redux state for this form. This state contains the following fields:
    • submitting (bool) - whether or not the form is in the process of submitting.
    • submitted (bool) - if the form has been successfully submitted to your endpoint.
    • failed (bool) - if the form submission has failed
    • validation (object) - contains a key for each of your form fields. If you perform any form validation on the backend (once the form has been submitted), this is where validation messages should appear.
    • redirect (string) - location for the form to redirect users too upon successful submission.