Reputation: 1833
I'm trying to update FormSection
name prop after I press my New Post
button because the prop name
of my FormSection
holds the postUid
, and when I press the button I generate a new uid, hence a new post.
Is there a nice way to do this?
The problem is that even if I destroy the form state, and even if I re-register the fields, the loaded component will still use the old state.
That's the real issue here, I don't want to refresh the page, ou unmount and mount the component. Any help? Thanks <3
Upvotes: 0
Views: 469
Reputation: 3888
You can assign/override form name using form
attribute, when using your Form component.
for example:
import NewPostForm from '../forms/NewPostForm';
<NewPostForm form={`dynamicName_${formId}`}
initialValues={{... ... }} />
Upvotes: 1
Reputation: 1738
As I understand you want to re-initialize the form. There is a setting enableReinitialize
in documantation
Example:
const ReduxedMyForm = reduxForm({
form: 'MyForm',
enableReinitialize: true,
})(MyForm);
Upvotes: 2