Urgent.News

What's breaking now, across thousands of outlets.

Tech

Build a Strapi v5 form with React without using a hosted widget

A React contact form is easy until it needs to be changed by someone who does not ship the frontend. Then the project needs a schema, an editor, server validation, spam controls, submission storage and a place to review what arrived. That work usually ends up split between a custom Strapi content type, a controller, an admin page and the React component that started the whole thing. This tutorial…

To create a React contact form using Strapi v5 without a hosted widget, follow these steps. First, install the @formflowjs/strapi-plugin-formflow plugin in your Strapi project and enable it in config/plugins.ts. Then, rebuild and start the project.

Open FormFlow from the admin sidebar and create a form with the slug contact-form. Add required fields for name, email, and message. Activate the form and inspect the public schema using a GET request to http://localhost:1337/api/formflow/forms/contact-form.

Next, install the headless React SDK by running npm install @formflowjs/react @formflowjs/core in your frontend project. Set the Strapi origin by defining VITE_CMS_URL in your .env file as http://localhost:1337.

Create an API client and fetch the schema using createFormFlowClient and getForm methods from @formflowjs/core. Then, use a useEffect hook to set the schema state when the component mounts. If the schema is not loaded, display a loading message.

Finally, bind the schema to your React markup using FormFlowProvider and FormFlowField components from @formflowjs/react. The FormFlowProvider owns the form store, while FormFlowField connects each form field to your input components. Use useFormFlow hook to manage the form state and handle success or error states accordingly.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Thursday 27 August →