
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
survey-tool-lib
Advanced tools
A powerful, flexible, and designer-friendly React survey library. Create beautiful surveys with a drag-and-drop builder, run them in your app, and export results with ease.
A powerful, flexible, and designer-friendly React survey library. Create beautiful surveys with a drag-and-drop builder, run them in your app, and export results with ease.
onJsonChange.npm install survey-tool-lib
# or
pnpm add survey-tool-lib
# or
yarn add survey-tool-lib
Use the SurveyCreator component to let users build or edit surveys.
import { useState } from "react";
import { SurveyCreator } from "survey-tool-lib";
import "survey-tool-lib/style.css"; // Don't forget to import styles!
function CreatorPage() {
const [surveyJson, setSurveyJson] = useState({
title: "My New Survey",
pages: [{ name: "page1", elements: [] }],
});
return (
<div style={{ height: "100vh", width: "100%" }}>
<SurveyCreator
json={surveyJson}
onSave={(finalJson) => console.log("Saved!", finalJson)}
onJsonChange={(newJson) => setSurveyJson(newJson)} // Keep local state in sync
brandColor="#007bff" // Customize the primary color
/>
</div>
);
}
Use the Survey component and Model class to display and run the survey for end-users.
import { Survey, Model } from "survey-tool-lib";
import "survey-tool-lib/style.css";
const surveyJson = {
title: "Customer Feedback",
pages: [
{
name: "page1",
elements: [
{
type: "text",
name: "name",
title: "What is your name?",
isRequired: true,
},
],
},
],
};
function SurveyPage() {
// 1. Create a Model instance
const model = new Model(surveyJson);
// 2. Define completion handler
const handleComplete = (sender) => {
// 'sender' is the Model instance
const results = sender.data;
console.log("Survey Results:", results);
// You can also access the full JSON if needed
// console.log("Survey Definition:", sender.json);
};
return (
<div className="my-survey-container">
<Survey model={model} onComplete={handleComplete} brandColor="#007bff" />
</div>
);
}
You can export survey definitions or results to PDF.
import { SurveyPDF } from "survey-tool-lib";
const handleExport = () => {
// Use the SurveyPDF class (compatible with SurveyJS API)
// 1. Instantiate with survey JSON (supports both full JSON or questions array)
const surveyPdf = new SurveyPDF(surveyJson);
// 2. Assign the results data
surveyPdf.data = surveyResults;
// 3. Save to PDF with a filename
surveyPdf.save("survey_results.pdf");
};
SurveyCreator Props| Prop | Type | Description |
|---|---|---|
json | object | The initial survey JSON object. |
onSave | function | Callback triggered when the "Save" button (if implemented) is clicked. |
onJsonChange | function | Callback triggered whenever the survey structure changes. |
brandColor | string | Hex color code for buttons and highlights. |
Survey Props| Prop | Type | Description |
|---|---|---|
model | Model | The survey model instance created with new Model(json). |
onComplete | function | Callback triggered when the survey is completed. Receives the model instance as an argument. |
brandColor | string | Hex color code for the "Complete" button and other accents. |
Model Classconstructor(json): Initializes the model.data: Getter for the current survey response data.setValue(name, value): Programmatically set a question value.getValue(name): Get a question value.validate(): Triggers validation for visible questions.MIT
FAQs
A powerful, flexible, and designer-friendly React survey library. Create beautiful surveys with a drag-and-drop builder, run them in your app, and export results with ease.
The npm package survey-tool-lib receives a total of 6 weekly downloads. As such, survey-tool-lib popularity was classified as not popular.
We found that survey-tool-lib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.