Skip to content

Pass render prop in Field #54

@maciejmyslinski

Description

@maciejmyslinski

Are you submitting a bug report or a feature request?

bug report and documentation improvement request

What is the current behavior?

I have a component that uses render prop.
Let's take an example:

const CustomSelect = ({ input, meta, render, children, ...restProps }) => (
  <select {...input} {...restProps}>{render && render()}</select>
);

I want to be able to use it with Field component like that:

const countries = [
  <option key="placeholder" value="placeholder" disabled>
    Select your country
  </option>,
  <option key="de" value="de">
    Germany
  </option>
];

<Field
  name="country"
  component={CustomSelect}
  render={() => countries}
/>

With current Field implementation, render prop will not be passed down to my CustomSelect component. However children prop would be passed. Consequently, we're not able to use form components that use render prop (this is such an awesome pattern, isn't it?).

The other problem is that this is inconsistent behavior because both render and children props are part of Field API. One of them is being passed down, the other is not.

What is the expected behavior?

Both children and render props should be passed down if component is used.
Also, the documentation should explain an order in which component, render, and children are used for rendering as well as what happens when you use more than one of them at the same time.

Sandbox Link

Edit lxnxzr3l19

What's your environment?

package version
React Final Form 1.1.1
Final Form 1.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions