简体   繁体   中英

React material-ui KeyboardDatePicker and Formik not working

I'm creating a form with material-ui and I'm using Formik and Yup for validation.

The TextField components work perfectly, however, the KeyboardDatePicker component presented the following error in the console

_onChange is not a function

and is now presenting

type is undefined.

Below is a cbs with the code. https://codesandbox.io/s/agitated-dust-wf6fn

you can use .setFieldValue to set value manually on onChange event.

 onChange={val => {
      console.log("___", val);
      formik.setFieldValue("dob", val);
 }} 

this method will work in any usecase.

只需像这样更改onChange函数:

onChange={(name, value) => formik.handleChange('dob', value)}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM