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?
Need a simple example of API only
Answers approved by surveyjs Support
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
JavaScriptwindow.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