const SmetaAccomodationItem:FC<>=()=>{
..............
const handleChangeRoadCosts = (id: number, keyVal: string, val: string) => {
const newList = data.map((dataEl: any, index: number) => {
if (id === index) {
const dataObj = {
...dataEl,
[keyVal]: val
}
let qty: number | undefined = undefined;
let price: string | undefined = undefined;
if (['inData','outData','peopleQty','costPerDay'].includes(keyVal) ) {
if (!val.trim()) {
qty = undefined
price = undefined
} else {
qty = parseInt(val)
price = keyVal === 'ticketQty' ? 'cost' : 'ticketQty'
}
dataObj.totalCost = !!(price && qty) ? (qty * parseInt(dataEl[price])).toString() : ''
}
return dataObj
}
return dataEl
}) //тут не законченная логика, но в целом функция сводится к преобразованию некоторых полей внутри объекта
}
.......
useEffect(() => {
.........
import {myFunc} from '....';
........
const handleChangeRoadCosts = (id: number, keyVal: string, val: string) => {
return myFunc(id, keyVal, val, data);
};