# Ein Kontaktformular mit React erstellen

> Formspree Docs · Die CLI verwenden · 14. Juli 2023

Lerne, wie du ein React-Formular erstellst, um Kontaktformular-Übermittlungen zu sammeln und E-Mail-Benachrichtigungen zu erhalten.

## 1\. Bereite dein Projekt vor

Installiere die React-Hilfsbibliothek in deinem Projekt:

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

Füge dann den `FormspreeProvider` zu deiner obersten App-Komponente hinzu. Wenn du beispielsweise Next.js verwendest, könnte deine Datei `pages/_app.js` so aussehen:

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

## 2\. Konfiguriere dein Formular

Füge in deiner Datei `formspree.json` ein Formular mit einer Aktion hinzu, die dich per E-Mail benachrichtigt:

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

Stelle dann deine Änderungen bei Formspree bereit:

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

## 3\. Erstelle dein Formular

Verbinde deine Formularkomponente mit dem `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;
```

**[Erfahre mehr über die Formspree CLI](/articles/using-the-cli/the-formspree-cli/) →**  
**[Erfahre mehr über Formspree und React](/articles/working-with-react/the-formspree-react-library/) →**
