issue: i want to calculate row data i will give quantity & price should calculate subtotal #11161
Unanswered
NarenderDhamarlapally
asked this question in
Q&A
Replies: 2 comments 1 reply
-
bill please help me for this . |
Beta Was this translation helpful? Give feedback.
0 replies
-
This line is causing a re-render of the component, and it's becoming an infinite loop: setValue(`lineItems[${index}][subtotal]`, output); To fix this issue, you can use the useEffect hook to update the value after the component has rendered: import React, { useEffect } from "react";
import { useWatch } from "react-hook-form";
export const Calc = ({ control, setValue, index }) => {
const results = useWatch({ control, name: `lineItems[${index}]` });
const output = results?.quantity * results.price;
useEffect(() => {
setValue(`lineItems[${index}].subtotal`, output);
}, [index, output, setValue]);
return <p>{output}</p>;
}; |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Version Number
7.14.1
Codesandbox/Expo snack
https://codesandbox.io/s/react-hook-form-v7-form-context-forked-7t7dfp?file=/src/index.js
Steps to reproduce
Expected behaviour
when quantity and price enter should populate subtotal data
and also add
// (prevProps, nextProps) =>
// prevProps.formState.isDirty === nextProps.formState.isDirty
please add this is Test component.
prevProps.formState is getting undefined
nextProps.formState is getting undefined
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions