-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
Form fn on update form data #1789
Conversation
…cksForm is used inside a <form> tag
…d make componentDidUpdate async in form
@nzambello I like the added method, though I'd be very interested also in your thoughts on #1711 With it, you can have a component get the whole form state with:
This way you also don't have to customize Edit.jsx to inject onChangeFormData. |
IMO these are two different things.
|
@tiberiuichim if we merge #1711 we should update this or the other way around. |
@nzambello no, the points you raise are absolutely valid. I'm fine with restructuring my PR after this one is merged |
I've been exploring the form implementation, it seems it's a hot topic in our little community. I have had a concern about the performance side of things. I've noticed slowdowns with volto-slate when dealing with large text pages. I've optimized some stuff there, I've also tested and it seems the slowdown is only seen in development mode, with a production built bundle I couldn't see it. But I'll quote the React docs:
In this PR we're doing it on each form update (which happens after every single click or key entered). For what is worth, lodash isEqual is not better, I've tested here: https://www.measurethat.net/Benchmarks/ShowResult/126840 In any case, that comparison is optional, so it would concern only those who pass the onChangeFormData param. |
src/components/manage/Form/Form.jsx
Outdated
* @returns {undefined} | ||
*/ | ||
UNSAFE_componentWillReceiveProps(nextProps) { | ||
if (nextProps.formData !== this.state.formData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> {a: 1} !== {a: 1}
true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nzambello you might be interested in our work in https://github.com/eea/volto-blocks-form It splits the form in multiple reusable components, I've also integrated your idea of |
We've started treating forms as "controlled inputs", having subforms without a state, for example in volto-columns-block. We model the form API after this component. Would it make sense to rename 'onChangeFormData' to 'onChange', to mimic the Field API? @plone/volto-team |
@giuliaghisini added a callback for the Form component to handle form state updates.