Here is my code:
import React from "react";
import "./sidebar.scss";
import HomeOutlinedIcon from "@material-ui/icons/HomeOutlined";
import InfoOutlinedIcon from "@material-ui/icons/InfoOutlined";
import ChatOutlinedIcon from "@material-ui/icons/ChatOutlined";
import LanguageIcon from "@material-ui/icons/Language";
import { NavLink } from "react-router-dom";
<div className="sidebar__Wrapper">
<div className="iconsContainer">
<div className="icons">
<NavLink to="/">
<HomeOutlinedIcon className="iconsDefaultStyle" />
</NavLink>
<NavLink to="/worldwide">
<LanguageIcon className="iconsDefaultStyle" />
</NavLink>
<NavLink to="/importantinfo">
<InfoOutlinedIcon
className="iconsDefaultStyle"
fontSize="default"
/>
</NavLink>
</div>
</div>
</div>
I am using Material UI icons inside NavLink
initially the color of the icon is gray but I want to change the color of Icon when the link is active, I mean What I want to do is:
When I click on the icon the color of the icon must be changed which will indicate that the current Link is active. I have done this by using separate state for every link which will change the classes when the particular icon is clicked but it makes my code very lengthy. Is there any other way to achieve this?