Gosha Arinich is right, you should return your <li> element. But, nevertheless, you should get nasty red warning in the browser console in this case

Each child in an array or iterator should have a unique "key" prop.

so, you need to add "key" to your list:

this.state.data.map(function(item, i){
  console.log('test');
  return <li key={i}>Test</li>
})

or drop the console.log() and do a beautiful oneliner, using es6 arrow functions:

this.state.data.map((item,i) => <li key={i}>Test</li>)

IMPORTANT UPDATE:

The answer above is solving the current problem, but as Sergey mentioned in the comments: using the key depending on the map index is BAD if you want to do some filtering and sorting. In that case use the item.id if id already there, or just generate unique ids for it.

Answer from Dmitry Birin on Stack Overflow
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
You will often want to display multiple similar components from a collection of data. You can use the JavaScript array methods to manipulate an array of data. On this page, you’ll use filter() and map() with React to filter and transform your array of data into an array of components.
🌐
W3Schools
w3schools.com › react › react_es6_array_map.asp
React ES6 Array map()
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep ... The map() method creates a new array with the results of calling a function for every array element.
Discussions

Rendering an array.map() in React
I am having a problem where I am trying to use array of data to render a element. In the code below the console logs are working fine, but the list items aren't appearing. var Main = React. More on stackoverflow.com
🌐 stackoverflow.com
What do you use MAP and SET data structure for in Reactjs
Not sure about MAP but I use SETs a lot to filter duplicates in any array! Making a SET (if done right) removes the duplicates Edit: duplicates… not “doubles” and as pointed out, it only removes primitive duplicates here’s a good article on that More on reddit.com
🌐 r/reactjs
37
20
August 3, 2023
React - Use Array.map() to Dynamically Render Elements - .map is different than in js
{item} ) normally JavaScript wouldn’t spit anything out of that… an object surrounded by strings without quotation marks… The previous challenges stated that we use normal js in render method, before return statement. So can anybody explain to me what this line is ? More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
8
0
January 25, 2023
.map() in React doesn't make sense
Because that JSX becomes regular JS that calls React.createElememt which takes an array of children as an argument. And each of those children are also calls to React.createElememt More on reddit.com
🌐 r/reactjs
15
0
January 27, 2023
🌐
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
We assign the new array returned by map() to the variable doubled and log it: const numbers = [1, 2, 3, 4, 5]; const doubled = numbers.map((number) => number * 2);console.log(doubled); This code logs [2, 4, 6, 8, 10] to the console. In React, transforming arrays into lists of elements is nearly identical.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › map
Array.prototype.map() - JavaScript | MDN
July 12, 2026 - The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array.
Find elsewhere
🌐
W3Schools
w3schools.com › react › react_es6_array_methods.asp
React ES6 Array Methods
The .map() method allows you to run a function on each item in the array, returning a new array as the result. In React, map() can be used to generate lists.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
React - Use Array.map() to Dynamically Render Elements - .map is different than in js
January 25, 2023 - {item} ) normally JavaScript wouldn’t spit anything out of that… an object surrounded by strings without quotation marks… The previous challenges stated that we use normal js in render method, before return statement. So can anybody explain to me what this line is ?
🌐
Codementor
codementor.io › community › different ways to map a list in react js
Different ways to map a list in React JS | Codementor
January 10, 2024 - ... This method creates a new array with the results of calling a provided function on every element in the original array. In React, you can use this method to render a list of items as a set of React components.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript | MDN
August 13, 2026 - Map objects are collections of key-value pairs. A key in the Map may only occur once; it is unique in the Map's collection. A Map object is iterated by key-value pairs — a for...of loop returns a 2-member array of [key, value] for each iteration.
🌐
CodeChef
codechef.com › learn › course › react-js › CREACT026 › problems › PREACT0121
Map() Method in Javascript in React JS for Front-end development
React Challenges · Pro · Stuck? Use our all-new Help✨ · Our interactive AI powered tool can boost your learning speed by 3x · Prev module · Next · StatementAI Help · The map() method is used to create a new array by transforming each item of an existing array using a function you provide.
🌐
Reddit
reddit.com › r/reactjs › .map() in react doesn't make sense
r/reactjs on Reddit: .map() in React doesn't make sense
January 27, 2023 -

I don't understand how this code is working:

<div> // Display all posts under this div
  {posts.map((post) => (
    <div key={post.id}>
      <h2>{[post.title}</h2>
      <h3>{"Written by " + post.author}</h3>
      <p>{post.text}</p>
    </div>
   ))}
</div>

As far as I understand, array.map() returns another array. How does this code work? The map function in this case isn't returning JSX elements, its returning an array of JSX elements. How come this works?

🌐
Medium
medium.com › @jaswanth_270602 › rendering-lists-in-react-introduction-to-map-function-ee3d5998a719
🌱 Rendering Lists in React — Introduction to map() function : React Series [Part-10] | by Jaswanth Kumar | Medium
May 21, 2025 - 💡 That’s why rendering lists dynamically using JavaScript’s map() function is essential in React! It helps us render UI elements for an array of data efficiently and cleanly.
🌐
Medium
medium.com › @hammadrao891 › understanding-the-map-function-in-react-a-comprehensive-guide-887cee7f7955
Understanding the Map Function in React: A Comprehensive Guide | by Hammad Rao | Medium
December 14, 2023 - - `element`: The current element being processed in the array. - `index`: The index of the current element in the array. ... The primary use case for the `map` function in React is rendering lists of elements dynamically.
🌐
Reddit
reddit.com › r/react › is it possible to create an array of components and map over it?
r/react on Reddit: is it possible to create an array of components and map over it?
August 2, 2022 -

solved the issue, missed a return statement in the mapping and removing the opening and closing tag inside the array. thanks for all of your help!

hey, googling hasn't helped me, because i've only found results for mapping over an array of date to create components. however, i wonder if it's possible to generate an array of actual components, to then render them? i would like to do that so i can use an index to increase a delay of an animation all of these components have for each component.

const navbarItems = [
<MotionOutlineHome />, 
<MotionOutlinePeople />, 
<MotionInfoOutline />, 
<MotionArrowDownward />, 
<MotionMessage />, 
<MotionOutlineLightmode />, 
<MotionOutlineDarkmode />
];

{navbarItems.map((Item, i) => {
<Item variants={variants} delay={(i * 0.5)} />;       
})}

having the array set up this way doesn't fix the issue as well:

const navbarItems = [
MotionOutlineHome, 
MotionOutlinePeople, 
MotionInfoOutline, 
MotionArrowDownward, 
MotionMessage, 
MotionOutlineLightmode, 
MotionOutlineDarkmode,  
];

any help would be appreciated :)

e: formatting is hard, for some reason this doesn't fit into one codeblock.

Top answer
1 of 3
2
fill the array without the <> around the components
2 of 3
2
If you're not having an error on the first approach, you might have a deeper issue with your setup (or you're missing a return, or your error logging is not properly working). The first approach would not work because you're passing an element instance as an element constructor, which would not work. It would throw an error like "React element must be string or function (type: object)". This happens because on the JSX transpiling it will be converted to React.createElement, which returns an object (like this: { type: Constructor, props: {}, children: [] }) So on the raw code, you would have: const navbarItems = [ React.createElement(MotionOutlineHome), React.createElement(MotionOutlinePeople), React.createElement(MotionInfoOutline), React.createElement(MotionArrowDownward), React.createElement(MotionMessage), React.createElement(MotionOutlineLightmode), React.createElement(MotionOutlineDarkmode), ]; {navbarItems.map((Item, i) => { React.createElement(Item, { variants, delay: i * 0, 5 }); })} Basically, you're creating an element from an element and not a constructor. I can see also other errors in this code: You're not returning in the map. You added {} on the mapper function but is using the short syntax. Basically, it's running inside the arrow function with no return. The correct would be: {navbarItems.map((Item, i) => React.createElement(Item, { variants, delay: i * 0, 5 }); )} If I'm getting this right, you're using , for decimal, the correct is to use . (0.5 instead of 0,5) The second approach is the correct one, but as you had the 2 errors prior, it didn't work as well. So the working code for what you want to achieve would be something like this: import React, { Fragment } from 'react'; const navbarItems = [ MotionOutlineHome, MotionOutlinePeople, MotionInfoOutline, MotionArrowDownward, MotionMessage, MotionOutlineLightmode, MotionOutlineDarkmode, ]; const NavBar = () => { return ( {navbarItems.map((Item, i) => )} ) }; A few takes here: If the navbarItems is declared outside the component and not manipulated between renders, as I did, you can use the index safely as a key. The key is vital so React can understand between renders if the prior element is the same as the new render (avoiding rerenders). If you have a dynamic array, where the key may change, it's better to have a stable ID for each one of them and avoid using the index.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-render-an-array-of-objects-in-reactjs
How To Render An Array Of Objects In ReactJS? - GeeksforGeeks
July 23, 2025 - The most common and recommended way to render an array of objects in React is by using the Array.map method to iterate through the array.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-use-map-to-create-lists-in-reactjs
How to use map() to Create Lists in ReactJS ? - GeeksforGeeks
July 23, 2025 - To create and render lists in React using the map function we will use useState to store the data as an array. Iterate this array using map and transform each item to a react component.
🌐
Medium
medium.com › @johnsonzagazor06 › understanding-the-basics-of-map-and-arrays-in-react-d380f37764bc
Understanding the Basics of map() and Arrays in React | by Okafor Johnson | Medium
September 10, 2024 - We use map() to iterate over the fruits array. For each fruit object, we display the name and color, utilizing inline styles for the color. ... In more complex applications, you may encounter nested arrays.
🌐
Medium
medium.com › @react-dojos › using-javascript-maps-instead-of-arrays-in-react-advantages-and-disadvantages-c6af61d2a89d
Using JavaScript Maps Instead of Arrays in React: Advantages and Disadvantages | by React Dojo | Medium
March 2, 2023 - Im a fan of changes and like to explore the new syntax and new approaches today I want to show you how to replace the traditional way of using array and map to load a set of data in React.