I need to access a field value to trigger special logic when it changes.
I can do:
const { input: { value: myField }} = useField("myField");
// do some stuff with myField
const state = useFormState();
const myField = state.values.myField;
// do some stuff with myField
What is the preferable way ? They are not exactly equivalent, for instance, when myField is not defined, useField will return ''
while useFormState will return undefined
.
If you just want the value of one (or maybe up to 3) field(s), use useField
.
Yes, useField()
gives you ''
. This is to ensure that the input is controlled.