# Build a Contact Form with React

> Formspree Docs · Using the CLI · Updated July 14, 2023

Learn how build a React form to collect contact form submissions and receive email notifications.

## 1\. Prepare your project

Install the React helper library in your project:

```
npm install @formspree/react
```

Then add the `FormspreeProvider` to your top-level app component. For example, if you are using Next.js, here's what your `pages/_app.js` file might look like:

```jsx
import { FormspreeProvider } from '@formspree/react';
function App({ Component, pageProps }) {
  return (
  	<FormspreeProvider project="{your-project-id}">
      <Component {...pageProps} />
    </FormspreeProvider>
  );
}
export default App;
```

## 2\. Configure your form

In your `formspree.json` file, add a form with an action to notify you via email:

```javascript
{
  "forms": {
    "contactForm": {
      "name": "Contact Form",
      "actions": [{ "type": "email", "to": "{your-email-address}" }]
    }
  }
}
```

Then, deploy your changes to Formspree:

```
formspree deploy -k <your-deploy-key>
```

## 3\. Build your form

Wire up your form component using the `useForm` hook:

```jsx
import React from 'react';
import { useForm, ValidationError } from '@formspree/react';

function ContactForm() {
  const [state, handleSubmit] = useForm("contactForm");
  if (state.succeeded) {
      return <p>Thanks for joining!</p>;
  }
  return (
      <form onSubmit={handleSubmit}>
      <label htmlFor="email">
        Email Address
      </label>
      <input
        id="email"
        type="email" 
        name="email"
      />
      <ValidationError 
        prefix="Email" 
        field="email"
        errors={state.errors}
      />
      <textarea
        id="message"
        name="message"
      />
      <ValidationError 
        prefix="Message" 
        field="message"
        errors={state.errors}
      />
      <button type="submit" disabled={state.submitting}>
        Submit
      </button>
    </form>
  );
}
export default ContactForm;
```

**[Learn more about the Formspree CLI](/articles/using-the-cli/the-formspree-cli/) →**  
**[Learn more about Formspree and React](/articles/working-with-react/the-formspree-react-library/) →**
