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"}
{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>
You can simply do
className={'btn ' + (isSubmitting ? 'btn-while-submitting' : '')}
Or using something like classnames
className={classNames('btn', {
['btn-while-submitting']: isSubmitting,
})}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.