react-component / react-component/field-form

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

Open
#468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
286
Avg merge
4d 16h
Merged PRs (30d)
1

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce both cases in the linked CodeSandbox, then inspect src/useWatch.ts around line 99 where the stringified objects are compared. Check the relationship with issue #431; done means the two input boxes stay consistent after setFieldValue followed by push.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.