Survey-library: Survey form doesn't re-render on chaning model in props (react)

Created on 3 Jan 2020  路  10Comments  路  Source: surveyjs/survey-library

Are you requesting a feature, reporting a bug or asking a question?

There is some problem I suppose, perhaps a bug or another way to use functionality.

What is the current behavior?

When I get json from back-end survey doesn't re-render and show nothing. Just empty survey form with typical span.

What is the expected behavior?

I want to request json from db and then implement it into survey model. This way works with 1.1.8 version but doesn't work with >1.1.24 (or another, I'm sure only about 1.1.8 version). Could you explain please, is it a bug or there is another way to do it?

Provide the test code and the tested page URL (if applicable)

Test code

const App: React.FC = () => {

    const [model, setModel] = useState<SurveyModel>(new (Survey as any).Model());

    useEffect(() => {
        axios.get('someURL')
            .then((response) => {
                setModel(new (Survey as any).Model(JSON.stringify(response.data)));
                console.log(response.data);
            })
    }, []);

    return (
        <div className="App">
            <Survey.Survey
                model={model}
                onComplete={(sender: SurveyModel) => console.log('complete survey form')}
            />
        </div>
    );
};

Specify your

Mozila firefox 60.9.0esr
React application
react-survey versions: 1.1.8 and 1.1.24

bug fixed

Most helpful comment

@Vladqqqqoo @RixBai The issue is fixed. The fix will be available in the next minor update (v1.5.11) that we will release on this week.

Thank you,
Andrew

All 10 comments

@Vladqqqqoo We can do some changes in react version. I remember we removed some obsolete react functions and change the way we are working with react state, according to react docs.

Does your render call on changing the model? Do you change SurveyJS version only?

Thank you,
Andrew

@andrewtelnov
Yes, I have changed only react-survey version. "Does your render call on changing the model?" - what exactly do you mean?

@Vladqqqqoo I have created the example with v1.1.29 and it works just fine for me.

Thank you,
Andrew

@ andrewtelnov
I'm sorry for late answer.
You used 1.1.1 version of "survey-react". Please have a look again.
I have tried the latest version of survey (1.5.0) and the result is the same.
So, really need your help, because it still doesn't work.
Thanks!

And pay attention please:

I do not keep a JSON on front-end part. I fetch it from back-end in componentDidMount and then setup new model with this JSON.

Do not add conditional render, because there's can be situation when it's inappropriate. For example if you have to change your survey model several times

@andrewtelnov Still waiting your recommendations

@Vladqqqqoo We are having same problem.
Did you find the solution?

@Vladqqqqoo @RixBai I have found the problem. We did not update correctly new props when new model or json is coming. We will work on the fix.

Thank you,
Andrew

@Vladqqqqoo @RixBai The issue is fixed. The fix will be available in the next minor update (v1.5.11) that we will release on this week.

Thank you,
Andrew

@andrewtelnov The issue is fixed!
Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AWIXOR picture AWIXOR  路  3Comments

spertusatti picture spertusatti  路  3Comments

wollerman picture wollerman  路  4Comments

nadialo picture nadialo  路  4Comments

GuiAfonso picture GuiAfonso  路  4Comments