Reputation: 113
Hi everyone I should insert a react-select with formik. I'm newbie you can tell me an example? I use Formik "^2.1.2" version, and "react-select": "^3.0.8" version. My error is: TypeError: Cannot read property 'type' of undefined. Thanks a lot.
<AsyncSelect
name="myfield"
cacheOptions
defaultOptions
loadOptions={fetchData}
onChange={selectedOption => {
formik.handleChange("myfield")(selectedOption);
}}
placeholder="search my field"
value={formik.values.myfield}
/>
Upvotes: 1
Views: 928
Reputation: 3501
Using formik, you should use formik.setFieldValue('myfield', selectedOption.value)
in the callback handler instead of handleChange
.
Upvotes: 4