I have a function to display user dashboard navigation. This function should set active funciotn to this elem waht is click default is 1 starter element/link.But i get infinite loop.
const UserLinks = [
{
name: "User Details",
linkTo: "/dashboard",
},
{
name: "Change Password",
linkTo: "/dashboard/changePassword",
},
];
const DasboardLinks = () => {
const [active, setActive] = useState(1);
return (
<SectionNavigation>
<ul>
{ UserLinks.map((link, i) => (
<li key={i} className={active === i ? "active" : ""}
onClick={setActive(i)}>
<Link to={link.linkTo}>{link.name}</Link>
</li>
))}
</ul>
</SectionNavigation>
);
};
When it is executed i get Too many re-renders. React limits the number of renders to prevent an infinite loop.How can i fix it to work.