Datasets:
File size: 2,576 Bytes
45721da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | issue: "isDirty" and "dirtyFields" work incorrectly after calling "reset" or "setValue"
### Version Number
7.17.2
### Codesandbox/Expo snack
https://codesandbox.io/s/elegant-goldberg-ebrms
### Steps to reproduce
1st Use Case
1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
2. Click on 'SET VALUE' button
3. See `isDirty === false` and `dirtyFields` is empty
2nd Use Case
1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
2. Click on 'SET VALUE' button
3. Change Text field
4. See `isDirty === true` and `dirtyFields === {"text":true}`
3rd Use Case
1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
2. Click on 'RESET' button
3. See `isDirty === false` and `dirtyFields` is empty
4rd Use Case
1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
2. Click on 'RESET' button
3. Change Text field
4. See `isDirty === true` and `dirtyFields === {"text":true}`
### Expected behaviour
1st Use Case
`isDirty` should be `true` and `dirtyFields` should contain both fields
2nd Use Case
`isDirty` should be `true` and `dirtyFields` should contain both fields
3rd Use Case
`isDirty` should be `true` and `dirtyFields` should contain both fields
4th Use Case
`isDirty` should be `true` and `dirtyFields` should contain both fields
Explanation: in all use cases the values are different from the default values, so the `isDirty` flag should be set to `true` and `dirtyFields` should contain all the fields that a different from the default values.
I believe this issue relates to the recently closed issue https://github.com/react-hook-form/react-hook-form/issues/6721 and the related discussion https://github.com/react-hook-form/react-hook-form/discussions/6710
### What browsers are you seeing the problem on?
Chrome
### Relevant log output
_No response_
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
## Relevant pre-fix discussion
### Issue #6764
#### Comment at 2021-10-11T23:06:05Z
case 1 and 2
Did you miss the following for `shouldDirty`?

case 4
- you should consider providing a `defualtValues` for the reset state without react hook form would refer to the original `defaultValues`.
```tsx
<Button
variant="contained"
onClick={() => {
formMethods.reset(); // equal defaultValues
}}
>
Reset defaults
</Button>
```
 |