I am new to react, I am working on a school project. In it, I am using Array.map method to render my component in DOM. It's working fine but I have a little confusion with map() method on the array. When I was learning Javascript I used Array.map and I was storing a new Array from map() method into a variable. for example const newArray = Array.map(e => e*2). So from MDN documents, I know map returns a new array. So now in react I saw some example and they are not storing Array.map result in a new variable so where is this new array exist after mapping the old array, which got modified, they are just using Array.map(e => e*2) not storing returned new array in any variable? For an example below where are they storing returned new array after mapping on incompleteTodos.
So, Am I missing something here from Array.map method? P.S Below code is working fine.
const incompleteTodos = this.state.todos.filter(todo => !todo.completed);
<div className="todos">
{incompleteTodos.length > 0 && <h2 className="incomplete">Incomplete</h2> }
{
incompleteTodos.map(todo => (
<Todo key={todo.id} removeTodo={this.removeTodo} completeTodo={this.completeTodo} todo={todo}/>
))
}
html element,string, andarray of element or string. Here you ` incompleteTodos.map` returningarray of Todo. thats why we don't need to store it in another variable