Need help in logic of ->afterStateUpdated()

I'm trying to update the net proceeds when the $state has change, it adds up a lot of value and I don't know where does it come from . Let's say the existing value of net proceed is 22,944 and current interest value is 306 . When I change the interest value into 307 it adds for about 251
->afterStateUpdated(function ($state, $set, $get) {
                                    $set('insurance', $state);
                                     
                                    // retrieve all original
                                    $loanAmount = str_replace(',', '', $get('loan_amount'));
                                    $cbu = str_replace(',', '', $get('capitalBuildUp'));
                                    $sd = str_replace(',', '', $get('savings_deposit'));
                                    $interest = str_replace(',', '', $get('interest'));
                                    $loanBalance = str_replace(',', '', $get('loan_balance'));
                                    $gli = str_replace(',', '', $get('group_life_insurance'));
                                    $penalty = str_replace(',', '', $get('penalty'));
                                    $others = str_replace(',', '', $get('others'));

                                    $deduction = $cbu + $sd + $interest + $loanBalance + $gli + $penalty + $others + $state;
                                    $netProceeds = $loanAmount - $deduction;
                                    $set('net_proceeds', number_format($netProceeds, 2));
                                   
                                }),
Solution
If the field reactivity is working, the issue is likely with the calculation you’re performing
Was this page helpful?