I have a complex state calculationResults
as
export interface ICalculationResult {
hw: IHwCalculationResult;
}
export interface IHwCalculationResult {
header: IHwCalculationResultHeader;
agreements: IAgreementItem[];
}
export interface IAgreementItem {
agreementRows: IAgreementRow[];
}
I want to remove the agreements pertaining to a product from the calculationResults.hw.agreements
and then push the agreements
received from the api.
I'm using immer since the object has many properties and the record count will be more than 5000
const nextState = produce(calculatedResults,(draftstate: any) =>{
if(allsite == "1"){
var indices: any = [];
draftstate.hw.agreements.forEach(function(value:any,pos: number){
if(value.boQItem.id == productNo)
{
indices.push(pos);
}
});
for(var index = indices.length-1;index>=0;index--)
{
draftstate.hw.agreements.splice(indices[index],1);
}
draftstate.hw.agreements.push(...data.hw.agreements);
}
});
Do I need to set the state as setCalculationResults(newState)
? But when I do it, there's a compiler error that newState is incompatible for calculationResults