user11781220
user11781220

Reputation:

Telling .map to skip over an object

In the following code maps over a useState called allTodos. It uses this data to render multiple components:

let todoComponents = allTodos.map(item => <Todos key={item.id} item={item} handleChange={handleChange}/>)

The problem is that the .map needs access the id in an object within an object with a unique name.

How can I tell .map to skip over the object, regardless of its name and get the id(other any other values).

Upvotes: 1

Views: 724

Answers (1)

Ali Faris
Ali Faris

Reputation: 18610

filter then map

allTodos.filter(i=> !i.completed).map(...)

Upvotes: 1

Related Questions