Open
Conversation
9e72a00 to
e517ac3
Compare
bsonntag
suggested changes
Jun 26, 2020
src/hooks/use-field-state.js
Outdated
| error: errors?.[field] ?? null, | ||
| meta: meta?.[field] ?? {}, | ||
| value: values?.[field] | ||
| error: errors ? get(errors, field) : null, |
Contributor
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.
Suggested change
| 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) |
Contributor
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:
Suggested change
| ...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)) { |
Contributor
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
0077ce1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the support for nested objects.
Issue #28