Registry / web-framework / survey-react-ui

survey-react-ui

JSON →
library2.5.20jsnpmunverified

survey-react-ui is a free, MIT-licensed React UI component library designed to render dynamic, interactive JSON-based forms and surveys directly within React applications. It enables developers to easily design and deploy complex, data-driven forms, polls, and quizzes, collecting user responses. The package is currently at version 2.5.20 and follows a rapid release cadence, with frequent minor and patch updates as indicated by the successive 2.5.x versions. Key differentiators include a rich set of over 20 built-in question types, support for custom question types, integrated themes with extensive CSS customization options, robust answer validation, and comprehensive TypeScript support. It is built upon `survey-core` for its underlying survey model logic and is broadly compatible with React versions 16.5, 17, 18, and 19. The library is backend-agnostic, with provided examples for Node.js, PHP, and ASP.NET environments.

npm install survey-react-ui
INSTALL
IMPORT
SIG · SURVEY-REACT-UI
S
survey-react-ui
web-frameworkjavascriptv2.5.20
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Survey
import { Survey } from 'survey-react-ui';
const Survey = require('survey-react-ui').Survey;
This is the primary React component for rendering a survey. Prefer named import for ESM.
Model
import { Model } from 'survey-core';
import { Model } from 'survey-react-ui';
The core survey model class is part of `survey-core`, not `survey-react-ui`. Importing from the wrong package is a common mistake.
StylesManager
import { StylesManager } from 'survey-core';
import { StylesManager } from 'survey-react-ui';
Styling and theme management utility; like Model, it resides in `survey-core`. Users often confuse this with `survey-react-ui`.

This quickstart demonstrates how to initialize a SurveyJS `Model` from a JSON definition and render it using the `Survey` React component. It includes basic state management for displaying results after completion and highlights the necessary CSS import for styling.

import React, { useState, useEffect } from 'react'; import { Survey } from 'survey-react-ui'; import { Model } from 'survey-core'; import 'survey-core/defaultV2.min.css'; // Or 'survey-core/modern.min.css' const surveyJson = { title: 'Sample Survey', description: 'Please answer the following questions.', pages: [ { name: 'page1', elements: [ { type: 'text', name: 'name', title: 'What is your name?', isRequired: true }, { type: 'dropdown', name: 'country', title: 'Which country do you live in?', choices: ['USA', 'Canada', 'Mexico', 'Germany', 'France'], isRequired: true } ] }, { name: 'page2', elements: [ { type: 'comment', name: 'feedback', title: 'Any additional feedback?' } ] } ] }; export default function MySurveyComponent() { const [surveyModel, setSurveyModel] = useState(null); const [surveyResults, setSurveyResults] = useState(null); useEffect(() => { const model = new Model(surveyJson); model.onComplete.add((sender, options) => { console.log('Survey results:', sender.data); setSurveyResults(sender.data); // In a real app, you would send sender.data to your backend }); setSurveyModel(model); }, []); if (!surveyModel) { return <div>Loading survey...</div>; } return ( <div> {surveyResults ? ( <div> <h2>Thank you for completing the survey!</h2> <pre>{JSON.stringify(surveyResults, null, 2)}</pre> </div> ) : ( <Survey model={surveyModel} /> )} </div> ); }
Debug
Known issues
breakingUpgrading from SurveyJS v1 (packages like `survey-react`) to v2 (`survey-react-ui`, `survey-core`) involves significant breaking changes to the JSON schema, API, and styling system. A direct upgrade without code modifications will lead to errors.
fix
Consult the official SurveyJS migration guides (e.g., 'Migrate from v1 to v2') for detailed instructions on updating your JSON, component usage, and custom logic.
affects: >=2.0.0
gotchaThe `survey-react-ui` package is strictly for the React UI component. The core survey logic and model (`Model` class, `StylesManager`, etc.) reside in the `survey-core` package. Accidentally importing `Model` or `StylesManager` from `survey-react-ui` will result in runtime errors or incorrect behavior.
fix
Always import core classes like `Model` and `StylesManager` from `survey-core`. For example: `import { Model } from 'survey-core';`.
affects: >=2.0.0
gotchaThe SurveyJS UI components require a CSS theme to be imported for proper rendering and styling. Without importing a theme, the survey will appear unstyled, often with misaligned elements.
fix
Ensure you import a SurveyJS theme stylesheet in your application, typically in your main component or entry file. For example: `import 'survey-core/defaultV2.min.css';` or `import 'survey-core/modern.min.css';`.
affects: >=2.0.0
gotchaThe `survey-react-ui` package declares `react` and `react-dom` as peer dependencies. Incompatible versions of React in your project (outside the supported ranges like `^16.5.0 || ^17.0.1 || ^18.1.0 || ^19.0.0`) can lead to build failures or unexpected runtime issues.
fix
Verify that your project's `react` and `react-dom` versions satisfy the peer dependency requirements of `survey-react-ui`. Update your React versions if necessary, or consider using a compatible version of `survey-react-ui`.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Objects are not valid as a React child (found: object with keys {text, value, isNew, locText, locValue, question, getBaseValue, isSelected, itemValue, selected, isDisabled, onPropertyChanged, getType, locManager, getType...})
Attempting to render an instance of `Survey.Model` directly within JSX instead of passing it as a prop to the `Survey` React component.
fix
Ensure you pass the `Survey.Model` instance to the `model` prop of the `<Survey />` component: `<Survey model={mySurveyModel} />`. Do not try to render `{mySurveyModel}` directly.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
This usually indicates that the `Survey` component was not imported correctly, often due to mixing CommonJS `require()` with ES Modules `import`, or an incorrect path.
fix
Use the correct ES Module named import: `import { Survey } from 'survey-react-ui';`. If using CommonJS, ensure your bundler handles it correctly, or use `const { Survey } = require('survey-react-ui');` (though ESM is recommended).
Module not found: Error: Can't resolve 'survey-react-ui/styles/default.css'
Incorrect or outdated path for the SurveyJS CSS theme import. Theme paths and names might change between major versions or be misspelled.
fix
Verify the exact path and filename for the desired SurveyJS theme. For v2, common paths are `survey-core/defaultV2.min.css` or `survey-core/modern.min.css`. Update your import statement accordingly.
Upgrade
Version history
2.5.20latest on npm
Audit
Dependencies
survey-corerequiredRequired for the underlying survey model, data handling, and core logic, separate from the React UI rendering.
reactrequiredPeer dependency for rendering the UI component within a React application.
react-domrequiredPeer dependency for rendering React components to the DOM.
Agent activity
3 hits · last 30 days
node
2
Resources