You should use component instead of string in item.type like this

import Foo from './Foo';
import Bar from './Bar';

[ { type: Foo, }, { type: Bar, }, { type: Baz}]

UPDATE:

If you do not have component reference in advance then use a mapping object which convert your string to component reference like this

import Foo from './Foo';
import Bar from './Bar';

const mapper = {
  Foo: Foo,
  Bar: Bar,
}

// Then use it like this

const getItems = this.props.itemslist.map((item, key) => {
    const Type = mapper[item.type];
    rendered.push(<Type data-attributes={attributes} key={key} />);
});
Answer from Prakash Sharma on Stack Overflow
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
On this page, you’ll use filter() and map() with React to filter and transform your array of data into an array of components. How to render components from an array using JavaScript’s map()
Discussions

How to render a JSX component for each item in array
Here there are 3 items in the array so i want to render 3 different components. Any help will be appreciated. ... @thedude yes becuse i don't now the what is inside of ListView. I just want to explain how we display a component using an array. More on stackoverflow.com
🌐 stackoverflow.com
How can I render an array of jsx elements in ReactJs
Here is how you might render a list of album artists. 1. Declare the state to hold albums (an empty array by default) retrieved. 2. On handleSearchClick, retrieve albums and set the albums state. 3. In render(), if album is not found, then display appropriate messages. More on stackoverflow.com
🌐 stackoverflow.com
July 19, 2018
Render Array of JSX element inside Helper function
Introduction: I'm trying to create Table Component which can reusable in nature. It can contain any number of column as per data pass to it through props from parent component. In order to achieve ... More on stackoverflow.com
🌐 stackoverflow.com
September 13, 2021
reactjs - React render array of components - Stack Overflow
Quick question. Anyone know how to render an array of components? Trying to make it easier for a developer to alter a particular component. (It's like a dashboard). Component list file import React More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How to render an array of objects in React?
Using these simple and easy steps, you can render an array of objects in React:

Step 1: Create a react application.
Step 2: Change directory.
Step 3: Create
data as an array.
Step 4: Mapping the array into a new array of JSX nodes as arrayDataItems.
Step 5: Return arrayDataItems from the component wrapped in
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
How do you render multiple objects in React?
You can use the Array's map functionality to render multiple elements in React. Simply map all your objects into React fragments, so that your Function component can make use of it. But don't forget to set a unique key prop!
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
How do you set an array of objects in state in React JS?

To set an array of objects in the state of a React component, you can use the 'useState' hook. So to do this, first, import 'useState' from 'react'. Then, declare a state variable using useState and initialize it with your array of objects. To update the state, use the setter function provided by the useState hook. And voila, now you can easily manage and modify the array of objects within your component's state.
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
🌐
Atomizedobjects
atomizedobjects.com › blog › react › how-to-render-an-array-of-components-in-react
How to render an array of components in React | Atomized Objects
To render an array of components in React you simply need to pass the array into JSX by wrapping it in curly braces, just be sure that your components each have a unique key prop because React will use this when rendering it to avoid bugs.
🌐
DEV Community
dev.to › ajithmadhan11 › rendering-arrays-in-react-14bh
Rendering Arrays in React - DEV Community
July 17, 2021 - This can be rectified by using ... return <p key={index}>{animal}</p> }) } </div> ); } In Jsx, to render more than one item you must wrap a wrapper around it....
🌐
DigitalOcean
digitalocean.com › community › conceptual-articles › understanding-how-to-render-arrays-in-react
Understanding How To Render Arrays in React | DigitalOcean
July 27, 2020 - Using something like a loop against an array or an object means you only have to write the HTML per item one time. Better yet, any future edits only have to be applied once. To render multiple JSX elements in React, you can loop through an array with the .map() method and return a single element.
🌐
GUVI
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
October 21, 2025 - To render an array of objects/items in React, we loop through the array using the .map() method and return a single item. In the below example, we loop through the courses array and return a <li> element for each item.
Find elsewhere
🌐
DEV Community
dev.to › collegewap › how-to-render-array-of-components-in-react-fma
How to render array of components in React - DEV Community
April 9, 2023 - ... import React from "react" const ... <ul>{items}</ul> } export default App · All you need to do is add the array within the flower brackets {items}....
🌐
Codemzy
codemzy.com › blog › react-render-array-of-objects
How to render an array of objects in ReactJS - Codemzy's Blog
August 31, 2022 - When you use Array.map() you loop over the array, and turn each item in the array from an object into JSX, so that it can be rendered. You are still rendering an array, but instead of an array like [ 1, 2, 3], it's more like [<p>First Item</p>, ...
Top answer
1 of 2
1

You need to render a list of components in render() function.
Not render multiple times for each album.

Here is how you might render a list of album artists.
1. Declare the state to hold albums (an empty array by default) retrieved.
2. On handleSearchClick, retrieve albums and set the albums state.
3. In render(), if album is not found, then display appropriate messages.
4. else create a list of artist components (wrapped in <li>).
5. Display the component by returning it.

WARNING: this is not a production/clean code.

class SearchResult extends React.Component {
    state = { albums: [] };

  searchAlbums = async (searchValue) => (await spotifyWebApi.searchAlbums(searchValue));

  handleSearchClick = async (e) => {
    const searchValue = e.target.value;
    const {items: albums} = await this.searchAlbums(searchValue);
    this.setState({albums});
  }

  render() {
    const {albums} = this.state;
    if (!album) return <div>loading...</div>;
    if (album.length === 0) return <div>No albums found</div>;

    // Generate artists components.
    const albumsComponents = albums.map(album => 
        album.artists.map(artists => (<li key={artists.name}>{artists.name}</li>)
    }

    return (
      <div>
        Search Term: 
        <input 
          value={this.state.searchTerm}
          onClick={this.handleSearchClick} />
        {albumsComponents}
      </div>
    );
  }
}
2 of 2
0

For now you're doing it in reverse. You have to map albums array inside of render function, not iside of a searchAlbums. What you can do, is to place albums array inside of state:

constructor(){
    super();
    this.state = {
        albums: []
    }
}

and in searchAlbums function set it in that state:

searchAlbums(){
  spotifyWebApi.searchAlbums(this.state.value)
    .then((response) => {
      this.setState({albums: response.albums.items});
    });
}

after that, in render function map it, like you did:

render(){
    return this.state.albums.map((t) => {
       return t.artists.map((artistsArray, index) => {
          return (
            <div>
            <li key={artistsArray.name}>
              {artistsArray.name}
            </li>
            </div>
          )
       });
    });
}
🌐
GitHub
github.com › facebook › react › issues › 9880
Rendering array of JSX components · Issue #9880 · facebook/react
June 7, 2017 - I need to create chunk of JSX and render at the end, so i check type of each object in the API response and push different component to the array. The main problem is that then, React completely ignore my tables inside td elements are render all as regular table.
🌐
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
We can refactor the previous example into a component that accepts an array of numbers and outputs a list of elements. function NumberList(props) { const numbers = props.numbers; const listItems = numbers.map((number) => <li>{number}</li> ); return ( <ul>{listItems}</ul> ); } const numbers = [1, 2, 3, 4, 5]; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<NumberList numbers={numbers} />);
🌐
DEV Community
dev.to › ark7 › rendering-a-list-of-elements-in-jsx-35am
Rendering a list of elements in JSX - DEV Community
June 6, 2024 - Create the Data Array: First, have an array of data that you want to render. This can be an array of objects or simple values. Use the .map() Function: Use the .map() function to iterate over the array and return a JSX element for each item.
🌐
Hackingwithreact
hackingwithreact.com › read › 1 › 13 › rendering-an-array-of-data-with-map-and-jsx
Rendering an Array of Data with map() and JSX – a free Hacking with React tutorial
Luckily for us, this is easy to do in JSX thanks to an array method called map(). When you call this on an array, you can have it run through all the items in that array and do something interesting with them – in our case, returning a new array of JSX that can be drawn.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-render-an-array-of-objects-in-reactjs
How To Render An Array Of Objects In ReactJS? | GeeksforGeeks
April 12, 2025 - The data is stored in an array of objects and displayed dynamically using the map() method. The RenderingArrayOfObjects component creates the table rows, and the App component displays the table with headers.
Top answer
1 of 10
21

Have you consider using the new React Fragments? (in v16)

This would be the simplest solution as it would by pass the whole array/key issue.

If you need to pass key, then I'd suggest to simply require the components to have the keys. This is how React works, so I wouldn't suggest you to hide this behavior behind an interface that might not be predictable.

If you really need to do this, then you can use React.cloneElement to clone the element and inject new properties:

React.cloneElement(element, { key: 'foo' });
2 of 10
15

If you’re always going to want to render all the components in your components file then you’re probably better off wrapping them in a React.Fragments tag.

Best practise is just to export this as a simple function that returns the components rather than as a constant.

So...

const Components = props => {
  return (
    <React.Fragment>

      <ComponentOne/>
      <ComponentTwo/>

    </React.Fragment>
  )
}

export default Components

That allows you to put multiple components next to each other without a DOM element containing them.

You should then just be able to render that by using it as a normal component and it’ll render all of them, so just import it then...

<Components />

Otherwise, if you want to treat them like an array, you have a function for free on the React object you’ve imported...

React.Children.toArray(arrayOfComponents)

You pass it an array of components (like in your original question) and it allows you to sort and slice it if you need to then you should be able to just drop it in the return of your render function

🌐
Linguine Code
linguinecode.com › home › blog › how to use array.map() to render data in react
How to use Array.map() to render data in React
December 18, 2020 - How do you render that data in ... age: 8 } ]; The answer is, you use Array.map() in your component and return JSX elements inside the Array.map() callback function to render the UI....