简体   繁体   中英

Redux-form: Can't get children from Field component

I'm trying to render a select, and want to be able to do something like this to add options:

<Field component={RenderSelect} name="subjects" label="Subjects">
        <option value="maths">Maths</option>
        <option value="english">English</option>
</Field>

I have a createRenderer function:

const createRenderer = render => ({input, name, label, children}) => {
  return (
    <div key={name}>
    <label htmlFor={name}>{label}</label>
    {render(input, name, children)}
    </div>
  )
},

and my RenderSelect looks like this:

const RenderSelect = createRenderer((input, name, label, children) => {
    return (
      <select name={name} {...input}>
      {children}
      </select>
    )
})

I was under the impression that I could just destructure the children prop off the Field like I do for input , name , label , etc, although this does not seem to work. When I run the code, no options appear in my select, and an inspection of the DOM verifies that there are no options. Any help would be much apprecited. Thanks in advance!

You just need to remove your label parameter

const RenderSelect = createRenderer((input, name, children) => {
    return (
        <select name={name} {...input}>
            {children}
        </select>
    )
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM