In react-router-dom
v6 the isActive
is a prop value destructured from a function passed to either of the children
, className
, and style
NavLink
props.
interface NavLinkProps extends Omit< LinkProps, "className" | "style" | "children" > { caseSensitive?: boolean; children?: | React.ReactNode | ((props: { isActive: boolean }) => React.ReactNode); className?: | string | ((props: { isActive: boolean }) => string); end?: boolean; style?: | React.CSSProperties | ((props: { isActive: boolean; }) => React.CSSProperties); }
Destructure isActive
in your style
callback, style={({ isActive }) => ({ color: isActive ? "green" : "blue" })}
.
<NavLink
to="/profile"
style={({ isActive }) => ({ color: isActive ? "green" : "blue" })}
className={s.navItems}
>
Profile
</NavLink>