Add callback when active state of NavLink is changed #11543
saurabhdaware
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Feature Request
An
onActiveChange
callback onNavLink
componentProblem
So we are using NavLink for our component library component where consumers can pass ReactRouter from
as
propInternally we set the as prop on our Link to turn our link into ReactRouter's NavLink
Now this works perfectly for simpler navigation links as ReactRouter will automatically add
aria-current
attribute andactive
class.But we also want maintain the isActive state internally in that react component so that we can do something like-
Currently there doesn't seem to be any way to achieve this (I know its possible with hooks like
useRouteMatch
oruseLocation
but since it's a component library component, we can't import anything from react-router-dom in it and the router is handled on consumer of library)I know there was an issue opened earlier for similar callback - #6161. But it seems like they were trying to do something else so opening this issue with more context to library's usecase
Beta Was this translation helpful? Give feedback.
All reactions