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

netlify-plugin-formspree

v1.0.1

Published

Netlify Build plugin - Netlify Plugin for Formspree

Downloads

174

Readme

Netlify Plugin for Formspree

This plugin automatically deploys forms configured in your formspree.json file using the Formspree CLI during the Netlify pre-build phase. For more help, please checkout these resources:

Prerequisites

Before installing, please create a new CLI project in the Formspree dashboard. Once created, you'll see a Project ID and a Deploy Key. You'll need these later when configuring your plugin, and creating your form.

For more information about creating CLI projects, please see the Formspree docs on creating a project.

Configuration via the Netlify UI

The netlify-plugin-formspree plugin can be found in the netlify build plugins directory.

Go to https://app.netlify.com/plugins/netlify-plugin-formspree/install to install the plugin into one of your sites, or you can navigate to your site's settings -> plugins.

Configuration via netlify.toml

First add the plugin to your project's package.json devDependencies:

npm install --save-dev netlify-plugin-formspree

// or 

yarn add -D netlify-plugin-formspree

Then, in your netlify.toml file include the formspree plugin:

[[plugins]]
  package = "netlify-plugin-formspree"

Once the plugin is installed, if there is a formspree.json file in your project root, it will run formspree deploy during your pre-build phase.

Environment Variables

At a minimum you'll need a FORMSPREE_DEPLOY_KEY environment variable populated with your project's deploy key. The deploy key was displayed when your project was first created. It can also be found under your project’s “Settings” tab in Formspree.

3rd party plugins can be configured to accept API keys via environment variables. See the docs on environment variables, and continuous deployment.

Adding endpoints with formspree.json

Creating forms with the Formspree CLI is accomplished by editing the formspree.json file. This file contains a list of form keys and associated configurations. Here is an example of a newsletter opt-in form configuration that signs up subscribers to a Mailchimp list:

{
  "forms": {
    "signupForm": {
      "name": "Sign-Up Form",
      "actions": [{ 
        "app": "mailchimp", 
        "type": "addOrUpdateContact", 
        "apiKey": "$FORMSPREE_MAILCHIMP_APIKEY" 
      }]
    }
  }
}

For a more in-depth explanation of the various configuration options see the formspree.json reference here: The formspree.json File

For a list of actions that can be added to your forms, check out the articles within the docs section on the Formspree CLI.

Setting up your forms in React

First you'll need to install the formspree-react library.

npm install @formspree/react

Then import FormspreeProvider and put it near the top of your component hierarchy, wrapping your forms. Supply the FormspreeProvider with your project ID obtained above.

For example, if you are using Next.js, here's what a top-level _app.js file might look like:

import { FormspreeProvider } from '@formspree/react';

function App({ Component, pageProps }) {
  return (
    <FormspreeProvider project="YOUR_PROJECT_ID">
      <Component {...pageProps} />
    </FormspreeProvider>
  );
}
export default App;

Next, set up your forms to use the useForm hook. It surfaces functions to handle form submissions, and manage form state.

Initialize the form in React by calling useForm and passing the form key you used in the formspree.json file.

const [state, handleSubmit] = useForm('{form-key}');

Here's and example of what a form component might look like for the signupForm endpoint we created above:

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

function SignupForm() {
  const [state, handleSubmit] = useForm('signupForm');
  if (state.succeeded) {
    return <div>Thank you for signing up!</div>;
  }
  return (
    <form onSubmit={handleSubmit}>
      <label htmlFor="email">Email</label>
      <input id="email" type="email" name="email" />
      <button type="submit" disabled={state.submitting}>Sign up</button>
    </form>
  )
}

For more information about creating forms with React see the article on the Formspree React Library.

Examples

You can see the formspree CLI in action, including an event signup form, including built-in Discord notifications below: