Giter Club home page Giter Club logo

Comments (3)

JaneSjs avatar JaneSjs commented on May 30, 2024

Hello @Priyeshvaghela77,

when user is typing the data gets cleared out due to re-renders

You may consider storing a survey model within a state variable to prevent re-rendering when a component state is changed.

function SurveyComponent() {
  const [surveyModel, setSurveyModel] = useState(null);
  ...
}

Please try storing a survey model within the state variable and let me know if this resolves the issue.

from survey-library.

Priyeshvaghela77 avatar Priyeshvaghela77 commented on May 30, 2024

Hello @JaneSjs,

We are already using a state for that.

This is what we are doing (sample code):

import { useEffect, useRef, useState } from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/defaultV2.min.css";
import * as SurveyCore from "survey-core";

export function LoadDynamicForm({ template }: { template: string }) {
  const [survey, setSurvey] = useState<Model | null>(null);

  useEffect(() => {
    const surveyModel = new Model(JSON.parse(template));
    setSurvey(surveyModel);
  }, [template]);

  return <>{survey && <Survey model={survey} />}</>;
}

package.json file:

    "react": "^18.2.0",
    "survey-creator-react": "^1.9.122",
    "survey-react": "^1.9.122",

In this, we are using the survey object to get the questions, set some default values, populate based on some conditions etc.

For, first few seconds when the form is opened, when user writes anything it gets cleared out due to state re-renders.

I also tried using redux state for this. But the issue still persists with redux also

from survey-library.

Priyeshvaghela77 avatar Priyeshvaghela77 commented on May 30, 2024

@JaneSjs

Can you please tell me how/when the surveyjs stores the data user entered? As far as I observed it is done onBlur (when the input loses the focus)

I tried logging the survey.data but it's always cleared when the webapp is re-rendering

from survey-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.