-
Notifications
You must be signed in to change notification settings - Fork 35
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
NavLink - Add a functionAsChild boolean prop to use children prop as a function #91
base: master
Are you sure you want to change the base?
NavLink - Add a functionAsChild boolean prop to use children prop as a function #91
Conversation
very nice, for the next major version I'll try to figure out if we can do it automatically. ..cant we just check |
I don't think so since it would return |
it's fine, here's an example: https://github.com/acdlite/recompose/blob/master/src/packages/recompose/isClassComponent.js |
and what if the children is not a class component but a function component ? const FunctionComponent = () => <div>Hello !<div>
const Menu = () => (
<nav>
<Navlink to={'/somewhere'}><FunctionComponent/></Navlink>
</nav>
) Does the function still works here ? |
Log it and see what else we can check for. It’s fine if it’s not in the public api |
@faceyspacey Do you have an Idea on how to reduce the cognitive complexity of the PR ? |
First add a 3rd check for an array of components. Then, the best way probably is to check the Now that said, there likely is other symbol types, and the best thing we can do is look at how React handles these checks, which they inevitably do: |
I dunno. I'm not in it like you are. |
From what I tried, The typeof implementation works, so now I need to decrease the code complexity |
I don't have any time currently. I'd get it working for your purposes, fork it, post any info you can, and I'll implement this in the next major version. |
Great thanks !! |
Thanks for making this PR @Aetherall, super helpful. I just hit this in my own project and made a similar branch, except I check the I'm going to make a PR just to see what the "cognitive complexity" is. ✌️ |
@sibnerian can you recheck this PR against the latest RFR2 and the latest released version of this package. If all is good I’ll merge and deploy |
@sibnerian bump |
@ScriptedAlchemy sorry for the delay. I updated my PR, see #112 . |
This will allow easy conditional rendering and will integrate well with many CSS-in-JS technologies ! :)
Usage:
If there is a super fancy way to distinguish normal childs and functionsAsChilds, it would be better to use that instead of having a functionAsChild prop
But for the time being I hope this will help somebody !