-
Notifications
You must be signed in to change notification settings - Fork 10
fix: initial value #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
NasgulNexus
commented
May 11, 2023
- In the controller, instead of the initial value, there will be a value.
- From the final form we pull out the initial value and value.
|
Preview is ready. |
| parentOnChange={null} | ||
| parentOnUnmount={null} | ||
| initialValue={_.get(tools.initialValue, name)} | ||
| value={_.get(tools.values, name)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U need to take values from store, not from tools
| } | ||
|
|
||
| const error = validate?.(value); | ||
| const isDiffentValues = !_.isEqual(value, initialValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*diffeREnt
Prefix is better to use for functions
You're checking dirty here, let's give a name for variable dirty too
| pristine: false, | ||
| touched: false, | ||
| modified: isDiffentValues, | ||
| pristine: isDiffentValues, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U can't use isEqual to check for pristine, only ===
| const tools = React.useMemo( | ||
| () => ({ | ||
| initialValue: store.initialValue, | ||
| values: store.values, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include values in tools
| errors: errors || {}, | ||
| })), | ||
| onUnmount: (name: string) => | ||
| onUnmount: (name: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointless changes, let's remove back
| tools: { | ||
| initialValue: FieldObjectValue; | ||
| initialValue: FieldValue; | ||
| values: FieldValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove values