React Form Component
The FlowGenie React Form component provides a ready-to-use form renderer that handles all the complexity of displaying and submitting forms. It’s the easiest way to integrate FlowGenie forms into your React application.
'use client'
import { Form } from '@flowgenie/sdk/react'
export default function PublicForm() {
return (
<Form
slug="contact-us"
successUrl="/thank-you"
submitLabel="Send Message"
/>
)
}Quick Start
1. Create Your Form
First, create your form using the FlowGenie form builder and publish it. You can access the form builder at app.flowgenie.pro .
2. Install the FlowGenie SDK
npm install flowgenie
# or
pnpm add flowgenie
# or
yarn add flowgenie3. Fetch Form Configuration on the Server
For private forms, fetch the form configuration server-side using your API key:
import { fetchForm } from '@flowgenie/sdk'
export default async function ContactPage() {
const form = await fetchForm({
id: process.env.FLOWGENIE_FORM_ID,
apiKey: process.env.FLOWGENIE_API_KEY,
baseUrl: 'https://app.flowgenie.pro'
})
return <ContactFormClient form={form} />
}For public forms, you can fetch them without an API key using the form slug:
const form = await fetchForm({
slug: 'contact-us',
baseUrl: 'https://app.flowgenie.pro'
})4. Render the Form on the Frontend
Create a client component to render the form:
'use client'
import { Form } from '@flowgenie/sdk/react'
import type { FormFetchResponse } from '@flowgenie/sdk'
export default function ContactFormClient({ form }: { form: FormFetchResponse }) {
return (
<Form
config={form}
slug="contact-us"
successUrl="/contact/success"
/>
)
}That’s it! The Form component handles rendering all question types, validation, conditional display, and form submission automatically.
Component Props
The Form component accepts the following props:
Required Props
config(optional): The form configuration object. Can be aFormConfigorFormFetchResponsefromfetchForm(). If not provided, you must provideformIdorslug.
Form Identification (one required if config not provided)
formId: The unique ID of the formslug: The slug of the form (for public forms)
API Configuration
apiKey: Your FlowGenie API key (required for private forms)baseUrl: The base URL for the FlowGenie API (defaults tohttps://app.flowgenie.pro)
Customization
classNamePrefix: Custom prefix for CSS class names (defaults tofg-)classNameKey: Alternative way to specify class prefixsubmitLabel: Custom text for the submit button (defaults to"Submit")loadingFallback: Custom React node to display while loading (defaults to"Loading form...")
Callbacks
onSuccess: Callback function called when form submission succeeds. Receives theSubmitFormResponseobject.onError: Callback function called when form submission fails. Receives anErrorobject.
Redirects
successUrl: URL to redirect to after successful submissionredirectUrl: Alternative prop name for success URL (same assuccessUrl)
Usage Examples
Basic Usage with Server-Side Fetch
// app/contact/page.tsx (Server Component)
import { fetchForm } from '@flowgenie/sdk'
import ContactFormClient from './ContactFormClient'
export default async function ContactPage() {
const form = await fetchForm({
id: process.env.FLOWGENIE_FORM_ID,
apiKey: process.env.FLOWGENIE_API_KEY,
baseUrl: 'https://app.flowgenie.pro'
})
return <ContactFormClient form={form} />
}// app/contact/ContactFormClient.tsx (Client Component)
'use client'
import { Form } from '@flowgenie/sdk/react'
import type { FormFetchResponse } from '@flowgenie/sdk'
export default function ContactFormClient({ form }: { form: FormFetchResponse }) {
return <Form config={form} successUrl="/contact/success" />
}Client-Side Fetch with Slug
'use client'
import { Form } from '@flowgenie/sdk/react'
export default function PublicForm() {
return (
<Form
slug="contact-us"
successUrl="/thank-you"
submitLabel="Send Message"
/>
)
}With Custom Styling
'use client'
import { Form } from '@flowgenie/sdk/react'
export default function StyledForm() {
return (
<Form
config={form}
classNamePrefix="my-form-"
submitLabel="Submit Application"
onSuccess={(response) => {
console.log('Form submitted:', response)
}}
onError={(error) => {
console.error('Submission error:', error)
}}
/>
)
}With Custom Success Handler
'use client'
import { Form } from '@flowgenie/sdk/react'
import { useRouter } from 'next/navigation'
export default function FormWithHandler() {
const router = useRouter()
return (
<Form
config={form}
onSuccess={(response) => {
// Custom success handling
console.log('Submission ID:', response.id)
router.push(`/submission/${response.id}`)
}}
onError={(error) => {
alert(`Error: ${error.message}`)
}}
/>
)
}Supported Question Types
The Form component automatically renders the appropriate input for each question type:
- Text inputs:
text,email,password,fillblank - Text areas:
multiline,code,orderedlist - Numbers:
number(with min/max support) - Dates:
date(with variants:date,time,datetime) - Selects:
select(dropdown, radio buttons, or button group) - Multi-selects:
multiselect(checkboxes or multi-select dropdown) - Checkbox: Single checkbox input
- File upload:
file(with file type restrictions and multiple file support) - Content:
header,paragraph,divider,markdown,image - E-signature:
esignature(canvas-based signature)
Conditional Display
The Form component automatically handles conditional display logic for both sections and questions. Questions and sections with showIf conditions will be shown or hidden based on user answers.
Styling
The Form component includes default styles that work out of the box. All CSS classes are prefixed (default: fg-) to avoid conflicts with your existing styles.
CSS Class Structure
fg-form: The form containerfg-page: Page containerfg-section: Section containerfg-section-header: Section title and descriptionfg-row: Row container (questions displayed horizontally)fg-question: Individual question containerfg-label: Question labelfg-helper: Helper textfg-input: Text inputs, textareas, selectsfg-radio-group: Radio button groupfg-checkbox-group: Checkbox groupfg-submit: Submit buttonfg-error: Error messagesfg-loading: Loading state
Custom Styling
You can customize the class prefix using the classNamePrefix prop:
<Form
config={form}
classNamePrefix="custom-form-"
/>This will generate classes like custom-form-form, custom-form-input, etc.
Overriding Styles
You can override the default styles by targeting the generated classes in your CSS:
.fg-input {
border: 2px solid #blue;
border-radius: 8px;
}
.fg-submit {
background: linear-gradient(to right, #blue, #purple);
padding: 12px 24px;
}Layout Structure
The form uses a flexible layout structure:
- Sections: Display as flex column (stacked vertically)
- Rows: Display as flex row (questions side-by-side)
- Questions: Flex column with
flex: 1to distribute evenly within rows
This means questions in the same row will appear horizontally next to each other, while different rows stack vertically.
Loading States
While fetching the form configuration, the component displays a loading state. You can customize this:
<Form
config={form}
loadingFallback={<div>Loading your form...</div>}
/>Error Handling
The Form component handles various error states:
- Fetch errors: Displayed if the form configuration cannot be loaded
- Validation errors: Displayed for individual questions (if validation is configured)
- Submission errors: Displayed if form submission fails
All errors are displayed with the fg-error or fg-submit-error class for easy styling.
Next Steps
- Learn about form structure and how forms are organized
- Explore question types and their options
- Understand validation flows for form validation
- See headless forms if you need more control over rendering