revolunet / react-mailchimp-subscribe

React subscribe form for Mailchimp.
https://revolunet.github.io/react-mailchimp-subscribe/
244 stars 49 forks source link

Reset form #66

Open AndreVizosodaCruz opened 3 years ago

AndreVizosodaCruz commented 3 years ago

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

bryantcodesart commented 1 year ago

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!

JayBox325 commented 1 year ago

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.

bryantcodesart commented 1 year ago

@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} />