简体   繁体   中英

How to use custom component in redux-form?

In my redux-form app I have a Field that should be a custom component:

import Name from './NameComponent'
..

<Field
            name="boer"
            component={Name}
            type="text"
            placeholder="First Name"
/>

The component is NameComponent:

import React from 'react'
const Name= field => <div><input type="text">fill in here:</input></div>
export default Name;

When I run this CRA app I get this error, why? :

 Uncaught Invariant Violation: input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`. Check the render method of Name. 

Use

const Name = field => <input type="text" {...field.input} />

Also I encourage you to learn this and this sections of Redux Form docs

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