Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 328
Italo Oliveira Avatar asked Mar 04 '20 05:03

Italo Oliveira


People also ask

Can I use material UI with Formik?

Formik can be easily used/integrated with Material UI, with just passing a few formik props to the respective Material UI Component props.

How do I use autocomplete material UI with Formik?

How to use React Material UI's Autocomplete component with Formik? To use React Material UI's Autocomplete component with Formik, we can call Formik's setFieldValue function with the name prop value of the Autocomplete and the value that is selected. We add the Form component with the Autocomplete component inside.

How do you use Formik With react?

First, create a new react application, react-formik-app using Create React App or Rollup bundler by following instruction in Creating a React application chapter. Next, install the Formik library. Next, open the application in your favorite editor. Next, create src folder under the root directory of the application.


1 Answers

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.

like image 157
vamshi krishna Avatar answered Sep 21 '22 07:09

vamshi krishna