Question T2648
Visible to All Users

Need a simple example of API only

created 5 years ago

Currently using React and Typescript and I would like a simple example of creating and rendering a survey (1 text question only will do) using only the current API. Not clear to me but it looks like we need to use a SurveyModel not a Survey?

Answers approved by surveyjs Support

created 5 years ago

Hello,

You need to use classes as shown in our online samples, e.g. https://surveyjs.io/Examples/Library?id=questiontype-checkbox&platform=Reactjs&theme=bootstrap

JavaScript
window.survey = new Survey.Model(json); survey .onComplete .add(function (result) { document .querySelector('#surveyResult') .textContent = "Result JSON:\n" + JSON.stringify(result.data, null, 3); }); ReactDOM.render(<Survey.Survey model={survey}/>, document.getElementById("surveyElement"));

The Survey.Survey is a react component that accepts the Survey.Model as a parameter. All API (described here - https://surveyjs.io/Documentation/Library/?id=surveymodel) is provided by the the Survey.Model class.

Thanks, Serge
SurveyJS Team