field-form icon indicating copy to clipboard operation
field-form copied to clipboard

useWatch doesn't call setState when it is object that same but not equal

Open haracejacob opened this issue 3 years ago • 0 comments

reproduce

https://codesandbox.io/s/sweet-banach-t7cpoq

case 1

  • If you click push button, foo is displayed in two input boxes

case 2

  • First, click setFieldValue button
  • Next, click push button, foo is displayed in the input box below, but not in above box.

cause

https://github.com/react-component/field-form/blob/master/src/useWatch.ts#L99

if (valueStrRef.current !== nextValueStr) {
    valueStrRef.current = nextValueStr;
    setValue(newValue);
}

it compares stringified objects. Strings are same but objects are not

I think this problem is conflicts with this issue(https://github.com/react-component/field-form/issues/431)

haracejacob avatar Jul 07 '22 09:07 haracejacob