Reputation: 959
How can I add a class to a button when a Formik Form isSubmitting?
I can see rendering different text if the form isSubmitting eg {isSubmitting ? "Please wait..." : "LOG IN"}
- but how can I add a class/ className to the button?
<button
type="submit"
className={`btn`}
onClick={() => {
api.submitForm();
}}
disabled={api.isSubmitting}
>
LOG IN
</button>
Upvotes: 0
Views: 273
Reputation: 18769
You can simply do
className={'btn ' + (isSubmitting ? 'btn-while-submitting' : '')}
Or using something like classnames
className={classNames('btn', {
['btn-while-submitting']: isSubmitting,
})}
Upvotes: 2