Skip to content

Populate value to read only field #1012

Answered by DanRibbens
jasonkw9 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @jasonkw9,

I've done this before for a project where I need to calculate some field based on sibling data changes. To do it I used the useWatchForm hook to calculate the updates in a useEffect. Here is an example:

const ProviderFee: React.FC<{ path: string }> = ({ path }) => {
  const { getDataByPath } = useWatchForm();
  const { value, setValue } = useField({ path });

  const type: string = getDataByPath('type');
  const amount: number = getDataByPath('amount');
  const feePercentage: number = getDataByPath('feePercentage');

  useEffect(() => {
    if (typeof amount === 'number' && typeof feePercentage === 'number') {
      setValue((feePercentage / 100) * Math.abs(amount));
    } e…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by denolfe
Comment options

You must be logged in to vote
2 replies
@DanRibbens
Comment options

@jasonkw9
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants