I have this sidebar component and I want to show the sidebar elements differently if the user is a simple user or is admin.
I have this isManager boolean saved in my state. If isManage is true, I want to loop on the complete links array. If isManager is false, I want to loop on the same array but without the last three elements (a simple array.splice).
But I get confused with JSX syntax and I don't know where to put the condition.
return (
<div className="flex-item--fill flex--column scops-sidebar-content-container">
<ul>
{links.map((link) => (
<li
key={link.id}
className="pad-half--left"
style={{
backgroundColor: `${
activeTabId === link.id ? '#4065d0' : 'var(--color-primary)'
}`,
}}
>
<button
className="btn--plain full-width align--left unpad"
style={{ color: 'white' }}
onClick={(e) => tabHandler(e, link.id)}
>
{link.name}
</button>
</li>
))}
</ul>
</div>
);
This is my component. Thanks a lot
isManagerflag to create a new array oflinksto render, where you perform your splice on the existinglinksarray, so you can remove the last 3 links that you don't want if theisManagerflag is false.