I have problem with rendering initialValues in AutoComplete component from Material UI library used in Formik Field. Values passed as initial are not rendered in component despite fact that if the form is submitted then they are passed in values variable.
I am also using material-ui-formik-components library if that fact matters.
Code shown below presents the issue.
import React from "react";
import { Formik, Form, Field } from "formik";
import { object, array } from "yup";
import { Autocomplete } from "material-ui-formik-components/Autocomplete";
const skills = [
{
"label": "PostgreSQL",
"value": "PostgreSQL"
},
{
"label": "Python",
"value": "Python"
},
{
"label": "React",
"value": "React"
},
{
"label": "Redis",
"value": "Redis"
},
{
"label": "Swift",
"value": "Swift"
},
{
"label": "Webpack",
"value": "Webpack"
}
]
const validationSchema = object().shape({
skills: array().required("At least one skill is required")
});
const initialValues = {
username: "",
gender: "",
country: "",
skills: [
{
label: "PostgreSQL",
value: "PostgreSQL"
}
],
birthdate: null
};
const SimpleFormExample = () => (
<div>
<h1>Simple Form Example</h1>
<Formik
initialValues={initialValues}
validationSchema={validationSchema}
validateOnBlur={false}
validateOnChange
onSubmit={values => {
console.log(values);
}}
>
{formik => (
<Form noValidate autoComplete="off">
<Field
name="skills"
options={skills}
component={Autocomplete}
textFieldProps={{
label: "Skills",
required: true,
variant: "outlined"
}}
multiple
/>
<button type="submit">Submit</button>
</Form>
)}
</Formik>
</div>
);
export default SimpleFormExample;
What should is do to display initialValues in formik?