I have an array of filters with the following Yup schema:
const schema = Yup.object().shape({
filters: Yup.array().strict().of(
Yup.array().strict().of(
Yup.object().shape({
// This isn't important
})
)
)
});
When I open the page, the form has the following data (ie the value of formik.value
):
{
"filters": [
[
{
"type": "samplemeta",
"cmp": "lt",
"key": "fastqc__%GC",
"value": [
"50"
]
}
]
],
}
Now for some reason, the validation fails with this error (ie the value of formik.errors
):
{
"filters": [
"filters[0] must be a `array` type, but the final value was: `{\n \"0\": {\n \"type\": \"\\\"samplemeta\\\"\",\n \"cmp\": \"\\\"lt\\\"\",\n \"key\": \"\\\"fastqc__%GC\\\"\",\n \"value\": [\n \"\\\"50\\\"\"\n ]\n }\n}`."
]
}
So even though the actual data is apparently valid, my array with the shape [{}]
is being converted to an object in the shape {0: {}}
, which is then failing the Yup validation. I don't see how this is happening, when I'm using the <FieldArray>
component to manage the filters array. You can see this here in the source code, which looks like:
<FieldArray name="filters" render={outerArrayHelpers => (...)}/>
Why is this happening, and how can I avoid it?