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

@formcarry/react

v1.0.4

Published

React Hooks library for Formcarry | formcarry.com

Downloads

403

Readme

Formcarry React

React library of formcarry.

Getting Started

Run this command to install with yarn:

yarn add @formcarry/react

or with npm:

npm install --save @formcarry/react

You have to have React as a dependency in your project in order to use this library.

Also this package uses React Hooks, therefore you have to use React >= 16.8.0

Example

A simple demonstration with React library:

import { useForm } from '@formcarry/react';

function MyFormcarry() {
  // Call the `useForm` hook in your function component
  const {state, submit} = useForm({
    id: 'Your-Form-ID-From-Formcarry'
  });

  // Success message
  if (state.submitted) {
    return <div>Thank you! We received your submission.</div>;
  }

  return (
    <form onSubmit={submit}>
		<label htmlFor="name">Name</label>
		<input id="name" type="text" name="text" />

		<label htmlFor="surname">Surname</label>
		<input id="surname" type="text" name="surname" />
		
		<label htmlFor="email">Email</label>
		<input id="email" type="email" name="email" />
		
		<label htmlFor="message">Message</label>
		<textarea id="message" name="message" />
		
		<button type="submit">Send</button>
    </form>
  );
}

You have to use a <form> element and pass submit as the onSubmit handler.

Destructuring with different field name

We return state and submit from useForm by default, but you can rename it to whatever you want, like this:

import { useForm } from '@formcarry/react';

function MyFormcarry() {
  const {state: formcarryState, submit: formcarrySubmit} = useForm({
	id: 'Your-Form-ID-From-Formcarry'
  });

  if (formcarryState.submitted) {
    return <div>Thank you! We received your submission.</div>;
  }

  return (
    <form onSubmit={formcarrySubmit}>
		<label htmlFor="name">Name</label>
		<input id="name" type="text" name="text" />

		<label htmlFor="surname">Surname</label>
		<input id="surname" type="text" name="surname" />
		
		<label htmlFor="email">Email</label>
		<input id="email" type="email" name="email" />
		
		<label htmlFor="message">Message</label>
		<textarea id="message" name="message" />
		
		<button type="submit">Send</button>
    </form>
  );
}

Example with Extra Data

import { useForm } from '@formcarry/react';

function MyFormcarry() {
  // Call the `useForm` hook in your function component
  const {state, submit} = useForm({
	id: 'Your-Form-ID-From-Formcarry',
	extraData: {
		// add whatever you want
		screenSize: `${window.screen.width}x${window.screen.height}`,
		language: window.navigator.language,
	}
  });

  ...
}

You can pass those to useForm:

| Key | Description | | :----------- | :------------------------------------------------------------ | | id | Your Form ID, which you can get it from formcarry | | debug | Boolean, it prints out logs to the console, true by default | | extraData | Accepts object, it will mix those object with form fields |

The state object contains the following:

| Key | Description | | :----------- | :------------------------------------------------------------ | | submitting | A Boolean indicating whether the form is currently submitting | | submitted | A Boolean indicating whether the form successfully submitted | | response | Returns formcarry successful response | | error | Returns formcarry error |