-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Allow injecting a custom component for NavLink to render to enhance support for HOCs #5496
Comments
Hey @Nimelrian ! how did u work around this as they didn't merge the PR? |
Closing per #5497 |
@irvingv8 I basically rewrote NavLink to use a wrapped Link (If I had more than one use case, I would have kept the renderComponent prop, but there is no need in my project as of now), simple copy, paste, replace, |
@Nimelrian Ok, TY! It'd be nice if they consider an alternative where instead of passing "what to render" into NavLink they allow you to pass some HOC to enhance Link. This way the initial purpose of NavLink remains the same but allows us to enhance the Link when needed. |
I also don't like that NavLink can't be wrapped in HOC. For temporary solution I nested all NavLinks inside divs and styled background of those divs on hover with Radium. Maybe it helps somebody.
|
You can walk around this with a You can pass what to render as a
Then in the render of your NavBar
result is
|
Background: I'm using Radium to style my React components.
Radium works by wrapping the target component's render function, searching for style props on DOM-node children and replacing them according to the current UI state (hovering/focusing/...). However, Radium does not do this for non-DOM-node children, since it does not know what the component is actually doing with the style prop. This is the case for React Router's
Link
andNavLink
componentsUsually, this is solved by wrapping the React component using Radium's HOC, as you can do with Link like in this snippet, which renders a
Link
with a red background, switching to green once you hover over it:But, if we were to replace
Link
withNavLink
in this example it wouldn't work, becauseNavLink
internally renders aLink
not wrapped by the Radium HOC.To solve this problem, I propose to add a new "renderComponent" prop to
NavLink
, which defaults to Link and gets rendered instead of a hardcodedLink
component. This allows users to wrap theLink
component rendered byNavLink
(Or even render something completely different).If this were implemented, it would allow injecting a custom render component like this:
This would also fix FormidableLabs/radium#907
The text was updated successfully, but these errors were encountered: