Implement a Sitecore form in a JSS React app
After creating a Sitecore form and added the form to a JSS app route in Sitecore, you can implement a JSS Form component that renders the Sitecore Form in your JSS application.
Using Sitecore Forms in JSS apps requires functioning session cookies. For this purpose:
-
You must have SSL enabled for your environment or disabled secure cookies in your Sitecore instance.
-
Your React JSS app must use the REST Layout Service.
To render a Sitecore form in a React JSS application:
-
In the root directory of your JSS application, install the necessary packages by running the following command:
-
To make the form render, you must tell the application how to render the Sitecore Forms schema. In the
srcdirectory of the rendering app, in a component file, for example,src/components/JssReactForm.tsx, implement your form component:NoteIn
headlessmode, you get an error if you send requests directly to the Sitecore instance. You must setsitecoreApiHostto an empty string, for example,sitecoreApiHost={''}, so requests are sent directly to your Node.js server. -
Start the JSS app in connected mode:
You can see the form data dumped to the page as JSON.