teslamotors / informed

A lightweight framework and utility for building powerful forms in React applications
https://teslamotors.github.io/informed
MIT License
949 stars 172 forks source link

Parent state resetting when Child is unmounted #414

Closed akshare closed 2 years ago

akshare commented 2 years ago

I have created an example here:

https://codesandbox.io/s/heuristic-chaum-imkoik?file=/src/App.js

In Parent component, after filling in the fields and clicking "Save", I set the state for "items".

After 5 seconds, I unmount the child component.

I am expecting items state in Parent to persist and not be effected by the Child being unmounted.

However, after Child is unmounted, the items state in Parent loses/resets the previously set values.

I can't pin point where the issue lies.

joepuzzo commented 2 years ago

Before we look into this can you please use the latest version of informed. we no longer support V3 and it looks like your code sandbox uses v3

akshare commented 2 years ago

Yes unfortunately, all of our forms are currently v3 and we are hoping to upgrade to v4, but that's going to be a big undertaking.

I was able to tweak some things and get the sandbox to use v4.

On a side note, the doc for v4 https://teslamotors.github.io/informed/?path=/story/form--api mentions formApi.getState but looks like it should be formApi.getFormState().

After figuring that out, I'm getting the results that i'm expecting when using v4. So it seems to be an issue with v3.

https://codesandbox.io/s/heuristic-chaum-imkoik?file=/src/App.js

I understand you don't support v3, so I'm probably going to have to figure out a different approach for unmount until we can get up to v4.

Thank you

joepuzzo commented 2 years ago

No problem. Thanks for pointing out that error in the docs! I will get that fixed!