简体   繁体   English

Formik表单正在提交时,如何向按钮添加类?

[英]How can I add a class to a button when a Formik Form isSubmitting?

How can I add a class to a button when a Formik Form isSubmitting? Formik表单正在提交时,如何向按钮添加类?

I can see rendering different text if the form isSubmitting eg {isSubmitting ? "Please wait..." : "LOG IN"} 如果表单isSubmitting,例如{isSubmitting ? "Please wait..." : "LOG IN"} {isSubmitting ? "Please wait..." : "LOG IN"} - but how can I add a class/ className to the button? {isSubmitting ? "Please wait..." : "LOG IN"} -但是如何向按钮添加class / className?

<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,
})}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 测试时如何在我的组件之外设置 Formik isSubmitting? - How can set Formik isSubmitting outside of my component when testing? 如何添加一个<field />当使用 React 和 Formik 在表单中单击按钮时? - How to add a <Field /> when a button is clicked inside a Form with React & Formik? Formik 的“isSubmitting”何时设置回 False? - When is Formik's "isSubmitting" set back to False? 无法使用 Formik 设置“isSubmitting” - Unable to set `isSubmitting` with Formik React-hook 表单从 isSubmitting 转换为 isSubmitted state 需要 5 多秒。 如何减少这种延迟以提高性能? - React-hook form is taking 5+ seconds to shift from isSubmitting to isSubmitted state. How can I reduce this lag to improve performance? isSubmitting 未在 Reactjs Formik 库中定义? - isSubmitting is not defined in Reactjs Formik library? React Formik:IsSubmitting 不适合我 - React Formik: IsSubmitting not working for me 在 ReactJS 中单击按钮时,如何添加活动的 class - How can I add an active class when a button is clicked in ReactJS 如何获取 Formik 表单上按下按钮的值? - How do I get the value of the pressed button on a Formik form? React/Formik 如何将按钮“提交”从“表单”块移动到页面上的另一个块?或者如何使用另一个按钮从表单中获取所有值? - React/Formik How can I move button 'submit' from 'form' block to another block on page?Or how can I use another button to get all values from my form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM