Skip to content

Accessing transformed value in useWatch #10556

Answered by leapful
rhwork asked this question in Q&A
Discussion options

You must be logged in to vote

@rhwork

useWatch hook has nothing to do with transformation logic from schema object validation since it's only watching change on input original value.

You can use .pick() then perform .cast() to get the transformed value.

For example:

const name = 'amount';
const amount = useWatch({ name, control: methods.control });
const { amount: transformedAmount } = schema.pick([name]).cast({ amount });

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rhwork
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