Closed brijesh-pant closed 4 years ago
Wouldn't this just consist of passing down the onClick prop? @brijesh-pant
Yes it’d be but as of now there isn’t an option to do that provided the AnchorLink
Would you not want to just pass down all props like ...props
?
@ansh Yes, it can be done via. ...props
as well, it depends what we want to customize. For me, it's just the click
handler as of now. https://stackoverflow.com/questions/63119384/gatsbyjs-burger-menu-close-menu-on-anchorlink-click
Take a look at this https://github.com/brohlson/gatsby-plugin-anchor-links/blob/master/src/components/AnchorLink.js#L20
We'd not want the existing click handler to be overridden by the onClick
prop we send, hence we need this piece of code to be customized so that a custom click
handler also runs before we do the URL switching logic.
Makes sense. I see where the problem is. Let me know if you think of an elegant solution and need help implementing.
@ansh I can just raise a PR for this if the author @brohlson agrees...
I'm also interested in this for building a collapsible menu!
FWIW - I usually write a useEffect
function which watches the location
in order to run side effects.
Naming this onClick
seems confusing to me.
I will add an onAnchorLinkClick
prop to the next version. #25
It's not possible right now to set a custom onClick event handler on the AnchorLink component, hence become difficult to make changes related to components (such as setting state variables). Would be nice to add such kinda functionality.