I am using Formik with FieldArray, and passing values of Formik to another component for cross calculations,
But now the output of values are array, so how can I get access to those individual input items from an array?
import React, { useEffect } from "react";
import {TextField} from "@mui/material";
const CalculatedFieldForArray = props => {
useEffect(() => {
var tax = 0;
var array = props.values.people
console.log(props.values);
array.map((out) => {
if (out.price) {
tax = out.price * out.country / 100;
}
//...Here I don't know how to assign value to FieldArray textfield
props.setFieldValue("quantity", tax);
})
props.setFieldValue("quantity", tax);
}, [props.values]);
return (
<TextField
type="number"
name="quantity"
value={props.values.quantity}
/>
);
};
export default CalculatedFieldForArray;
values which is passed by Formik is as below which shown in console, Want to access price and country value for each input and return calculation value.
{
"people": [
{
"id": 0.8646983183745629,
"price": "11",
"country": "20"
},
{
"id": 0.3192991708409705,
"price": "110",
"country": "18"
}
],
"quantity": 0
}
``