I'm using React and I don't want to reply <ListItem ...> code as many times as the cases are. There is a method to simplify and reduce this code?
displayToDoList = () => {
switch (this.state.sorted) {
case 0:
return (this.state.todosById.map(todo =>
<ListItem
key={todo.id}
plainText={todo.plainText}
name={todo.name}/>))
break;
case 1:
return (this.state.todosByName.map(todo =>
<ListItem
key={todo.id}
plainText={todo.plainText}
name={todo.name}/>))
break;
case 2:
return (this.state.todosByCreatedAt.map(todo =>
<ListItem
key={todo.id}
plainText={todo.plainText}
name={todo.name}/>))
break;
case 3:
return (this.state.todosByCharcacters.map(todo =>
<ListItem
key={todo.id}
plainText={todo.plainText}
name={todo.name}/>))
break;
}
}
I think that there will be a better way than mine.