Posts

Showing posts from December 11, 2018

Clean way of close and reopen tag when variable change in React

Image
up vote 1 down vote favorite I have an array like this: [ { group: "A", id: "1", name: "Mike" }, { group: "A", id: "6", name: "Sherley" }, { group: "B", id: "3", name: "Charlie" }, { group: "C", id: "2", name: "Dave" } ] and I want to group the array based on its group. The array is already sorted by group and name. So, I make something like this: let lastgroup = c[0].group return <Group title={lastgroup}> {c.map(x => { if (lastgroup == x.group) { return <a href={"#" + x.id}>{x.name}</a> } else ...