react-hook-form: Optionally trigger onChange event when setting value through ref
I read a couple of this repo issue but I can’t quite find my use case - I can’t quite know if I am asking a stupid question or if it’s a feature that doesn’t exists.
I have a special input that has some cosmetic changes depending on the value : it’s a material-ui-like input with schrinking placeholder. the ref is forwarded to the real input inside.
The input can be controlled or not, but even when not, we rely on a local state that listen to the onChange function of the input to determine if there is a value or not in the field.
Now, using this awesome library, and trying to use either setValue of some default values for the form, my inputs are properly changed through REF but the placeholder won’t schrink as changing the input value is not reflected on the styled pseudo input’s state.
My question is : in this case, do we have a way to trigger the onChange event when the library touches the input value ? Is there a workaround or a good practice to address this ?
Cheers, and thanks a lot for the great work.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (10 by maintainers)
I was just thinking of those cases when you indeed have some logic that needs to know about the input being changed. But actually it can be achieved equally by using
watchandsetValue, and it makes it clearer so my proposition is probably not a good idea.