Skip to content

formspark/use-formspark

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

Formspark logo

use-formspark

React hooks for Formspark.

Works with React and React Native.

Continuous deployment

Installation

# NPM
npm install @formspark/use-formspark

# Yarn 
yarn add @formspark/use-formspark

Usage

import React, { useState } from "react";
import { useFormspark } from "@formspark/use-formspark";

const ContactForm = () => {
  const [submit, submitting] = useFormspark({
    formId: "your-form-id"
  });
  const [message, setMessage] = useState("");
  return (
    <form onSubmit={async (e) => {
        e.preventDefault();
        await submit({ message })
    }}>
      <textarea
        value={message}
        onChange={(e) => setMessage(e.target.value)}
      />
      <button type="submit" disabled={submitting}>Send</button>
    </form>
  );
};

Note: do not mistake action url (e.g. https://submit-form.com/capybara) and form id (e.g. capybara), this package only uses the latter.

License

MIT