react-redux-form icon indicating copy to clipboard operation
react-redux-form copied to clipboard

<Field /> component suggestions:

Open joshacheson opened this issue 7 years ago • 3 comments

  1. Currently <Field /> allows a consumer to provide a function at props.children, and in this case, passes the relevant fieldValue to that function.
  • I'm curious whether we should also pass modelValue? I don't understand internals of rrf well enough to know whether this is ever not fully redundant with fieldValue.value.
  • I wonder if we should support passing props.render to do exactly what props.children does (when props.children is a function). We could easily support render and children both to avoid breaking changes, and this would have a consistent API with <Control />.
  1. Currently <Field /> does not augment the context with its resolvedModel. Instead, the context remains unchanged under a field component. This gives me unexpected results when doing:
<Fieldset model='.one'>
  <Field model='.two'>
    {(fieldValue) => (
      // in here fieldValue is the fieldValue for '...one.two'
     <Fieldset model='.three'>
       {
         // in here context.model is '...one.three' instead of '...one.two.three'
       }
     </Fieldset>
    )}
  </Field>
</Fieldset>

My suggestion is that we have Field augment context.model in the same way that <Fieldset /> does.

joshacheson avatar Jan 23 '18 20:01 joshacheson

The reason I'm using <Field/> in this way is specifically because I want to read fieldValue at this point in the tree. Perhaps the better way to handle my suggestion is to, well, add a render prop to <Fieldset /> which passes the relevant fieldValue.

joshacheson avatar Jan 23 '18 21:01 joshacheson

Worth mentioning, I guess, that I'm very happy to do all the work for whatever's decided here. Just interested in feedback on the ideas.

joshacheson avatar Jan 25 '18 18:01 joshacheson

@joshacheson These seem like good ideas, and I'd be happy to review a PR swiftly if you decide to implement them.

davidkpiano avatar Jan 25 '18 19:01 davidkpiano