-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array delete is not working (UI became out-of-sync of model) #22
Comments
@cguedes Thanks a lot. This is the best issue I have seen on github. |
I just tried it, yeah that is really a killer app. Thanks for the tip! |
@cguedes I have tried to use UUID but the updated field keeps refreshing. It is not easy to fix it and I need more time to figure it out. |
I don't know if is already solved as it's here for quite some time, I have an idea, not tested. How about transforming arrays into objects when setting the scope and invers transformation (how to detect it has been an array?) when exporting the scope. lodash: PS: not necesarely needed to use |
I ran into this issue and the key to fixing it (pun intended) is to have a unique key on the list item in the Array component. I used lodash <li key={_.uniqueId(i)} className="list-group-item"> I'd already defined my own Array component (basically just a copy of it), so was able to do this without changing the original component in the src. Thanks @cguedes for pointing me in the right direction! |
@devel-pa @kevadkins I have tried with unique keys and it doesn't work for me. React refreshes and creates brand new object and my browser dead eventually. My implementation was not the same as yours though. Could you please test your solution to verify if it works? |
I resolved this by embedding SchemaForm inside another component, once that component has been created we don't touch that model. |
That is very interesting. If you don't touch the model. you don't have the issue. what if you remove one of the items in the array? Are you updating the model in schema form or updating the model in your wrapper component? |
I have a component that maps over a group of types, each type holds a form/schema/model. I render the one that is selected. |
@maplechori Is your component open sourced? Or could you please share your component so that someone can be inspired to find a generic solution to resolve the problem? |
@stevehu you can check this in the live demo you provide (sample: simple array) print screen animated gif |
@stevehu I'll try to implement a similar component this week. |
Excellent. Thanks. |
Seems the bug that I saw is not the one mentioned here. No luck with this one yet. |
I encountered this problem last week. I tried to resolve it, but I wasn't able to isolate the problem. The models are definitely correct, but the UI itself is not. |
In the following GIF image you can see that:
This happens because you are using array's index as the key for each
li
component rendered in the Array react component.React uses key prop to improve performance. From the documentation you can read the following:
I don't know a solution for this. But the solution should be around defining a stable KEY for the array elements internally tracked by react-schema-form.
The text was updated successfully, but these errors were encountered: