survey-react-ui
v3.2.4
Published
React form library for rendering dynamic, JSON-based forms and surveys. Collect user responses and store them in your own database.
Keywords
Readme
SurveyJS React Form Library
SurveyJS React Form Library is a free and open-source React component library for rendering dynamic, JSON-driven forms and surveys in React applications.
The survey-react-ui package integrates SurveyJS Form Library with React, renders forms defined with SurveyJS JSON form definitions, and collects user responses in the browser. It works together with the framework-independent survey-core package, which provides the form model and handles form structure, validation, conditional logic, calculations, navigation, localization, and other core behavior. Installing survey-react-ui brings survey-core with it — you build a model from JSON with survey-core and pass it to this package's Survey component (<Survey model={survey} />) to render it.
Use SurveyJS React Form Library to build multi-step forms, surveys, quizzes, assessments, calculator forms, and other data-entry tools. Form definitions and submitted responses can be stored and processed in your own backend and database.
You can create form definitions manually, generate them with AI, or build them visually with SurveyJS Creator, an embeddable drag-and-drop form builder.
Installation
npm install survey-react-uiUsage
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.css";
const surveyJson = {
elements: [
{ name: "firstName", title: "Enter your first name:", type: "text" },
{ name: "satisfaction", title: "How satisfied are you?", type: "rating" }
]
};
export default function SurveyComponent() {
const survey = new Model(surveyJson);
survey.onComplete.add((sender) => {
console.log(JSON.stringify(sender.data, null, 2));
});
return <Survey model={survey} />;
}survey-core/survey-core.css applies the Default theme. For other predefined themes and CSS-variable customization, refer to Themes & Styles.
Server-Side Rendering
SurveyJS supports SSR: survey-core does not access the DOM during rendering, and HTML id attributes are generated deterministically per survey instance, so server and client markup match and hydration succeeds. If you render multiple surveys on the same page, assign a unique elementIdPrefix to each model.
Under Next.js or another framework with React Server Components, mark the component that renders a survey as client code with the 'use client' directive — SurveyJS components are interactive and rely on state and event handlers. See Add a Survey to a React Application.
Theme Adapters
A theme adapter maps an existing design system's CSS variables onto SurveyJS design tokens, so an embedded survey inherits the look of the host application. Adapters ship with survey-core as plain CSS — import one after the base style sheet:
import "survey-core/survey-core.css";
import "survey-core/themes/adapters/shadcn-default.css";Adapters are available for Bootstrap (plus Bootswatch variants), Material UI, shadcn/ui, and Tailwind CSS v4 (tailwind4.css), with matching icon sets (survey-core/themes/adapters/icons/lucide, .../icons/mui). See Theme Adapters.
Key Features
Dynamic Forms and Surveys
- Render dynamic JSON-driven forms and surveys in React applications
- Multi-step forms, quizzes, assessments, calculator forms, and survey pop-ups
- Conditional visibility, branching, calculations, and expression-based logic
- Input validation, save-and-resume workflows, and dynamic content
Form Controls
- 20+ built-in question and input types
- Dynamic panels and repeating question groups
- Custom question types and reusable components
- Electronic signature, image capture, file upload, matrices, and other advanced controls
React Integration
- React components
- TypeScript support
- Framework-independent form model through
survey-core - Client-side rendering without a required SurveyJS backend
- Support for SSR
Data and Backend Integration
- Connect to any server, API, or database
- Store form definitions and submitted responses in your own infrastructure
- Load choices from web services
- Integrate third-party components and services
- Backend integration examples for PHP, ASP.NET Core, and Node.js
Appearance and Localization
- Built-in themes and custom branding
- Theme Adapters for Bootstrap, Material UI, and shadcn/ui
- Multi-language forms and right-to-left language support
- Community-supported UI localization
Related packages
| Package | Purpose |
| --- | --- |
| survey-core | Platform-independent survey model (installed automatically) |
| survey-angular-ui | Angular renderer |
| survey-vue3-ui | Vue 3 renderer |
| survey-js-ui | HTML/CSS/JavaScript renderer |
Documentation
- Website
- Documentation
- Get Started with React
- Form Library Demos for React
- Release Notes
- Roadmap
- What's New
For AI coding agents: https://surveyjs.io/llms.txt indexes the documentation. Any documentation page is also available as raw Markdown — append .md to its URL, for example https://surveyjs.io/form-library/documentation/get-started-react.md.
SurveyJS Ecosystem
| Product | Purpose | License |
| --- | --- | --- |
| Form Library | Render dynamic forms from JSON (this package) | MIT |
| Survey Creator | Drag-and-drop form builder UI | Commercial |
| Dashboard | Visualize and analyze collected results | Commercial |
| PDF Generator | Render forms and responses as PDF | Commercial |
| AI Form Response Extractor | Extract responses from paper forms, PDFs, and images into a SurveyJS schema (ai-form-response-extractor) | MIT |
Build from Source
Requires Node.js 20 or later — CI builds on Node 20.x and 22.x. This monorepo does not use npm workspaces: each package installs independently, but a root install is still required for the shared tooling (linting, Playwright).
Clone the repo and install shared dependencies
git clone https://github.com/surveyjs/survey-library.git cd survey-library npm installBuild
survey-corefirstThis package resolves
survey-corefrom../survey-core/build, so the model must be built before this library can be built or tested. Follow Build from sources in thesurvey-coreREADME.Install dependencies and build this library
cd packages/survey-react-ui npm install npm run buildBuild output goes to the
builddirectory. Usenpm run watch:devwhile developing.Run a test application
npm run startThis serves the package directory at http://localhost:8080/.
Run unit tests
Unit tests use Vitest in a jsdom environment and live in
tests. The markup snapshot tests are generated intotests/shardsbygen-shards.jsbefore each run, sonpm run testis the entry point rather than a barevitest.npm run test # whole suite npm run test:watch # watch mode npx vitest run tests/ssr-postid.spec.ts # a single file npx vitest run -t "test name" # tests matching a substring npm run test:update # update markup snapshotsRun end-to-end tests
E2E, visual-regression, and accessibility tests are Playwright suites. Do not start an HTTP server yourself — the Playwright config starts its own.
npm run e2e:ci # e2e npm run e2e:ci -- --grep "TestName" # a single test npm run scr:ci # visual regression npm run accessibility-tests:ci # accessibility
Licensing
SurveyJS Form Library is distributed under the MIT license.
