I'm working on an accordion feature in an application that shows brackets based on the number of items displayed from an array.
Based on the sizes of the brackets, I've come up with a solution using standard css for a single bracket
|_
.bracket {
height: 35px;
width: 20px;
background-color: transparent;
border-left: 1px solid grey;
border-bottom: 1px solid grey;
}
and flex-box for a bracket to use in a multiple item array in order to produce the effect as shown above.
|_
|
.bracket_container {
display: flex;
flex-direction: column;
.bracket {
height: 35px;
width: 20px;
background-color: transparent;
border-left: 1px solid grey;
border-bottom: 1px solid grey;
}
.bottom {
height: 35px;
width: 20px;
background-color: transparent;
border-left: 1px solid grey;
}
}
Visually this works fine with my mapped array as all the boxes appear connected, however, now I want to conditionally render these style classes in ReactJS based on the following.
#1 I want to show the single .bracket if only 1 item in the array is shown or it is the last item in the array.
{/* OPEN CONTAINER */}
{tracks?.uid === showConnections &&
tracks?.feed.map((item) => (
<div key={item.uid} className={style.sub_container_wrapper}>
//Here is where I want to conditionally render the brackets
{feed.item !== 1 ? (
<div className={style.bracket_container}>
<div className={style.in_bracket} />
<div className={style.bottom} />
</div>
)
: (
<div className={style.bracket} />
)}
Tracks is the upper area of the accordion & feed is my array in the dropdown area which has the array (from an external JSON file).
The logic isn't working because I'm not sure what should be extracted from the feed object or in what way should I get the first or last item in the array.

mapwill also pass the index of the element as an argument you can use that to determine if you're on the last item.tracks?.feed.map((item, index)