A dynamic React form builder using Material UI
npm install material-form-builder> A dynamic, composable, and type-safe form builder built on top of Material-UI (MUI 5 & 6) β designed for developers who want power and flexibility in building complex, data-driven forms.
Created and maintained by Mahdi Amiri (@owlpro)
---
Material Form Builder helps you build complex, nested, and fully dynamic forms using only JSON configs or JSX β without losing control of layout, validation, or interactivity.
Itβs perfect for admin panels, CMS dashboards, product editors, or anywhere you need fast, customizable forms.
---
β
Dynamic JSON structure β define your form with plain objects
β
Nested group inputs β build multi-level data structures
β
Reactive form system β handle visibility, validation, and dependencies
β
Full MUI support β all unknown props are passed to the underlying MUI components
β
Custom Input API β create reusable input types with full setValue / getValue / clear control
β
TypeScript ready β fully typed generics for safe development
β
Works with React >=17 and MUI 5 & 6
---
``bash`
npm install material-form-builderor
yarn add material-form-builder
Make sure you have these peer dependencies installed:
`bash`
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled dayjs
---
`tsx
import React from "react"
import { Box, Button } from "@mui/material"
import { FormBuilder, useFormBuilder } from "material-form-builder"
export default function ExampleForm() {
const { ref, getValues, setValues, clear } = useFormBuilder<{ text: string | null }>()
return (
inputs={[
{ type: "text", selector: "text", label: "Text", variant: "outlined" }
]}
/>
)
}
`
---
`tsx`
{
selector: "basic",
type: "group",
wrapper: inputs => (
),
inputs: [
{ selector: "name", type: "text", label: "Product Name", required: true, fullWidth: true },
{ selector: "price", type: "text", label: "Price", required: true, fullWidth: true },
{ selector: "currency", type: "select", label: "Currency", options: [
{ label: "USD", value: "usd" },
{ label: "EUR", value: "eur" }
]}
]
},
{
selector: "images",
type: "group",
wrapper: inputs => (
),
inputs: [
{ selector: "items", type: "custom", element: MultiMediaInput }
]
}
]}
/>
---
`tsx
import { Box } from "@mui/material"
import { forwardRef, useImperativeHandle, useState } from "react"
import { CustomInputProps } from "material-form-builder"
export interface ExampleInputProps extends CustomInputProps {}
export type ExampleInputValueType = string | null
export default forwardRef(function ExampleInput(_: ExampleInputProps, ref) {
const [value, setValue] = useState
useImperativeHandle(ref, () => ({
setValue: (v: ExampleInputValueType) => setValue(v),
getValue: () => value,
clear: () => setValue(null),
}))
return
})
`
Then use it inside your form:
`tsx`
inputs={[
{
type: "custom",
selector: "example",
element: ExampleInput,
label: "Custom Example",
},
]}
/>
---
You can even build nested FormBuilders inside custom inputs.
Hereβs a simplified version of the internal SeoInput component:
`tsx
import FormBuilder, { CustomInputProps } from "material-form-builder"
import { forwardRef, useImperativeHandle, useRef, useState } from "react"
export default forwardRef(function SeoInput(_: CustomInputProps, ref) {
const builderRef = useRef
const [title, setTitle] = useState("")
useImperativeHandle(ref, () => ({
setValue: async v => builderRef.current?.setValues(v),
getValue: () => builderRef.current?.getValues().data,
clear: () => builderRef.current?.clear()
}))
return (
inputs={[
{ selector: "title", type: "text", label: "Meta Title", onChangeValue: setTitle },
{ selector: "description", type: "text", label: "Meta Description", multiline: true },
{
selector: "og",
type: "group",
wrapper: inputs =>
inputs: [
{ selector: "title", type: "text", label: "OG Title" },
{ selector: "description", type: "text", label: "OG Description", multiline: true }
]
}
]}
/>
)
})
`
This is a real-world example from production usage β showing how FormBuilder can recursively manage other forms.
---
| Prop | Type | Description |
|------|------|-------------|
| inputs | InputProps[] | Array of input configurations |onChange
| | (values) => void | Called when any input value changes |onMount
| | (values) => void | Called after first render |ref
| | FormBuilder | Ref to access form methods (getValues, setValues, clear) |
| Key | Type | Description |
|-----|------|-------------|
| type | "text" \| "number" \| "group" \| "custom" \| ... | Input type |selector
| | string | Unique key for field |label
| | string | Input label |required
| | boolean | Field required or not |visible
| | (data) => boolean | Function to show/hide field |wrapper
| | (child, actions) => ReactNode | Custom layout wrapper |updateListener
| | any[] | Dependencies for reactive updates |element
| | React.ComponentType | For type: "custom" |inputs
| | InputProps[] | For nested groups |
| Method | Returns | Description |
|---------|----------|-------------|
| getValues(validation?: boolean) | { data, validation } | Get form data and validation state |setValues(values)
| | Promise | Set form values |clear()
| | Promise | Reset all fields |
---
All hooks and components are strongly typed.
You can safely define the expected form shape:
`ts``
const { ref, getValues } = useFormBuilder<{ name: string; price: number }>()
const values = getValues().data // { name: string; price: number }
---
MIT Β© Mahdi Amiri