react-mailchimp-subscribe icon indicating copy to clipboard operation
react-mailchimp-subscribe copied to clipboard

Reset form

Open AndreVizosodaCruz opened this issue 3 years ago • 3 comments

There is some way to reset the form after return success?

AndreVizosodaCruz avatar Jul 05 '21 23:07 AndreVizosodaCruz

To future travelers, I was able to reset the form by changing the key on the MailchimpSubscribe component. Beware, this will force that component to mount/remount--which is probably what you want but may have side effects depending on how you wire it up!

bryantcodesart avatar Feb 02 '23 03:02 bryantcodesart

To future travelers, I was able to reset the form by changing the key on the MailchimpSubscribe component. Beware, this will force that component to mount/remount--which is probably what you want but may have side effects depending on how you wire it up!

A working example of this would be really helpful.

JayBox325 avatar Jun 26 '23 13:06 JayBox325

@JayBox325 I no longer have access to that codebase, but literally as simple as the below. :) Not the most elegant thing, but just exploiting the react-ism that changing a key forces a component to re-render (and wipe its state)!

 <MailchimpSubscribe key={someValueYouChangeWhenYouWantToReset} />

or, on a parent:

 <MyModalThatContainsMailchimpSubscribe key={someValueYouChangeWhenYouWantToReset} />

bryantcodesart avatar Jun 26 '23 15:06 bryantcodesart