Uh oh!
There was an error while loading. Please reload this page.
Add support for nested objects - #29
Conversation
9e72a00 to
e517ac3Compare| error: errors?.[field] ?? null, | ||
| meta: meta?.[field] ?? {}, | ||
| value: values?.[field] | ||
| error: errors ? get(errors, field) : null, |
There was a problem hiding this comment.
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.
| return { | ||
| ...state, | ||
| [payload.field]: payload.value | ||
| ...set(state, payload.field, payload.value) |
There was a problem hiding this comment.
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.
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
0077ce1Compare
This PR adds the support for nested objects.
Issue #28