useFieldArray fields in the mui datagrid cells, each has input values and demand calculation in every onchage of fields #12667
Unanswered
rustamas762
asked this question in
Q&A
Replies: 1 comment
-
That's how I would do it. I don't think there's a better option than One potential optimization would be to pass the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
currently i handle my these fields calculation like so
const onChangeQuantity = (event, index) => { const quantity = Number(event.target.value); setValue(
estimateItems.${index}.amount`, calculateAmount(index), {quantity,
});
};
const calculateAmount = (index, updatedField = {}) => {
// Merge the updated field into the current item
const currentItem = _estimateItem[index];
const { quantity, price, discount, isDiscountPercentage } = {
...currentItem,
...updatedField, // Override with the updated field
};
};
`
This is an simple example. I wonder if there is better way (in terms of better performance) to get and set field values? I'm not an expert on hookform, especially useFieldArray hook, but there are couple of methods that seems to be have differences, such as update, replace.
I research official doc nonstop, but maybe some of you faced such situation and has a recommendation. Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions