-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for nested objects #29
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
base: master
Are you sure you want to change the base?
Conversation
9e72a00 to
e517ac3
Compare
src/hooks/use-field-state.js
Outdated
| error: errors?.[field] ?? null, | ||
| meta: meta?.[field] ?? {}, | ||
| value: values?.[field] | ||
| error: errors ? get(errors, field) : null, |
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.
With get there's no need to check if errors exists. You can also pass the fallback value as the third argument.
| error: errors ? get(errors, field) : null, | |
| error: get(errors, field, null), |
Please do the same in the two lines below.
src/hooks/use-form.js
Outdated
| return { | ||
| ...state, | ||
| [payload.field]: payload.value | ||
| ...set(state, payload.field, payload.value) |
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.
set mutates the object you pass as the first argument, so this mutates the previous state, which should be avoided. Instead, please pass an empty object as the first argument:
| ...set(state, payload.field, payload.value) | |
| ...set({}, payload.field, payload.value) |
Please do the same on other set calls you have.
|
|
||
| function getNestedKeys(state: Object, allKeys: Array<string>): Array<string> { | ||
| return Object.keys(state).reduce((acc, key) => { | ||
| if (fieldMetaKeys.includes(key)) { |
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.
I'm not sure about this... What if you have a field in the form named active?
What do you think about keeping the meta object as a flat object with keys with dots? Like this:
meta: {
'foo.bar': {
active: false,
// etc
}
}Let's discuss this on Monday, ok?
e517ac3 to
0077ce1
Compare
This PR adds the support for nested objects.
Issue #28