Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i render a component by a for loop?

i have an array of components, so i want to print the content, my attempt is like this:

 const fields = [<Invites />]

    return (
        <Card
            style={{ width: 600 }}
        >
            
                {fields.map((Item, index) => <Item />)}

i got this error:

react-dom.development.js:28439 Uncaught Error: Element type is
invalid: expected a string (for built-in components) or a
class/function (for composite components) but got: object.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

btw this is the Invites component:

const Invites = () => {
    return (<Form.Item className='form-item item-container' label="Invites">
        <span >
            <Input  />
        </span>

    </Form.Item>)
}

>Solution :

You just need to change your code to this:
{fields.map((item, index) => item)}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading