question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When using formio/react inside a component, every time the parent component change, formio/react is destroyed and recreated.

See original GitHub issue

Environment

React-formio version: “5.0.0-rc1” (Possibly all versions) Formio.js version: “4.12.7” Frontend framework: React “16.14.0” Frontend framework: React-Dom “16.14.0” Browser: many browsers. Browser version: many browser versions.

Context

Our software need to save the schema of formio in a database along with other information about a specific entity. The schema can also be altered by an editor. Ex: Updating a label text without the need to use formio. So, react-formio is embed inside a component called FormioWrapper. Finally, this component is used inside EditEntityComponent with a save button. Each time there is a change in EditEntityComponent props/states, formio reset itself.

Steps to Reproduce

  1. Go to https://codesandbox.io/s/cra-react-formio-forked-esi5m?file=/src/index.js
  2. Click on Advanced tab to open it.
  3. Delete, add or move a text box.

Observed behavior

Formio reset itself by closing the Advanced tab, the actual state is lost.

Expected behavior

Formio don’t have to reset itself every time a modification is triggered.

Where to look

After investigation, we found that this block of code is what cause the situation.

src/components/FormBuilder.jsx line 56 to 59

  useEffect(() => {
    initializeBuilder(props);
    return () => builder ? builder.instance.destroy(true) : null;
  }, [props.form.display, props.form.components, props.options]);

Why do the component need to destroy itself every time a change is triggered? Is there a limitation that avoid the component to stop destroying itself?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

1reaction
mp3threecommented, Apr 6, 2021
1reaction
mp3threecommented, Mar 29, 2021

This is now associated with a ticket in our system to look into further - FIO-2660

Read more comments on GitHub >

github_iconTop Results From Across the Web

formio - Bountysource
When using formio/react inside a component, every time the parent component change, formio/react is destroyed and recreated. $ 0.
Read more >
formio/formio - Gitter
I am attempting to create a custom component in Form.io. The custom component is as shown in the shared wireframe. A list of...
Read more >
React - Can A Child Component Send Value Back To Parent ...
React's one-way data-binding model means that child components cannot send back values to parent components unless explicitly allowed to do ...
Read more >
react-formio | Yarn - Package Manager
To see an example application of how to implement all the components and modules in this library, see https://github.com/formio/react-app-starterkit ...
Read more >
Form Templates - Form.io Documentation
The Form.io template platform allows you to completely change the rendered HTML for any component within the Form.io platform.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found