In case you're starting a brand new project, you'll need some initial steps. One of the most straightforward ways is to use the create-react-app package. To start:
npm install create-react-app --global
mkdir ~/react-project && cd ~/react-project
npx create-react-app .
npm start
Use your favorite code editor to work with files in ~/react-project/src. You will be able to make a contact form there.
To effortlessly handle form submissions, you can use the herotofu-react package. It will do all the form submission process work for you.
Create a new file called Form.js in the src folder. You can use any fields and any framework for styling it. For now, we're staying with the standard "Name," "Email," and "Message" for the simple contact form. We're also going to use TailwindCSS to make it beautiful, but you can use your own custom CSS code too.
Open App.js in your src folder, add contact form component, and enable TailwindCSS. If it's an existing project, open the file where the contact form should appear. You need to:
You can also utilize the useJsonData hook to send JSON data instead of form data. This is useful when you want to send data to an API that requires a JSON payload and maybe don't want to use a form. The usage is similar to useFormData.
See the React contact form guide for a complete guide how to implement HeroTofu forms backend.