-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: initial value #39
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. |
@@ -85,7 +85,7 @@ export const DynamicField: React.FC<DynamicFieldProps> = ({ | |||
name={name} | |||
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
@@ -71,18 +73,19 @@ export const useField = <Value extends FieldValue, SpecType extends Spec>({ | |||
} | |||
|
|||
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 ===
@@ -28,36 +32,42 @@ export const useStore = (name: string) => { | |||
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
onChange: (name: string, value: FieldValue, errors?: Record<string, ValidateError>) => | ||
setStore((store) => ({ | ||
...store, | ||
values: _.set({...store.values}, name, _.clone(value)), | ||
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
|
||
export interface DynamicFormsContext { | ||
config: DynamicFormConfig; | ||
Monaco?: React.ComponentType<MonacoEditorProps>; | ||
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