React formik form validation: How to initially have submit button disabled

前端 未结 3 1559
孤城傲影
孤城傲影 2021-02-05 08:20

Below is my React form validation code in which I am using formik. By default when the form loads, I want to keep the submit button disabled:



        
3条回答
  •  甜味超标
    2021-02-05 09:23

    To have the button initially disabled just check if the touch object is empty and keep it this way until all the fields are validated with !isValid

    disabled={!isValid || (Object.keys(touched).length === 0 && touched.constructor === Object)}
    

提交回复
热议问题