Skip to content

Conversation

mattiamanzati
Copy link
Contributor

Please refer to #3874

Feel free to purpose different name for children function parameters! I am not good at naming things. :(
This should also allow creating Link on react-native, not tested yet, I don't have the infra to test it right now!

const RNLink = ({to, ...props}) => <Link to={to}>{
   ({isActive, transition}) => <Text onPress={transition} {...props} />
}</Link>

@mattiamanzati
Copy link
Contributor Author

Uhm, where should we put an example onto the docs?

@timdorr
Copy link
Member

timdorr commented Sep 16, 2016

You would add a file here: https://github.com/ReactTraining/react-router/tree/v4/website/examples
And update the website routes here: https://github.com/ReactTraining/react-router/blob/v4/website/routes.js

Just run npm run dev to start the website building and watching while you work.

Edit: Run that from within the website directory. Be sure to npm install first, of course.

@timdorr timdorr added this to the v4.0.0 milestone Sep 16, 2016
@timdorr timdorr added the feature-request Used to close PRs that haven't gone through/been accepted the Proposal process yet label Sep 16, 2016
modules/Link.js Outdated

// If children is a function, we are using a Function as Children Component
// so useful values will be passed down to the children function.
if(typeof children == 'function'){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style nitpick: but can you add spaces around the comparison parens? if (typeof children == 'function') {

modules/Link.js Outdated
) {
event.preventDefault()
this.context.router.transitionTo(this.props.to)
this.handleTransition()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this needs to be extracted here. I'd leave this out of the PR for now.

modules/Link.js Outdated
[ className, activeClassName ].join(' ').trim() : className
}
/>
>{children}</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of including the children inside of the <a> (which makes a nested set of a's, which is against spec and your browser will mess with), I would if/else between children or the <a> and use cloneElement. I would also require a single child so you can do that easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, sorry but I have'nt understand well. Instead of doing <a {...rest}>{children}</a> I should do <a {...rest} /> right? I don't have understand the cloneElement part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore that part, I was thinking wrong 😄

@timdorr
Copy link
Member

timdorr commented Sep 16, 2016

Looking good! Thanks for being on the ball with this!

@timdorr timdorr merged commit ab57fa8 into remix-run:v4 Sep 16, 2016
@mattiamanzati mattiamanzati deleted the v4 branch September 16, 2016 18:08
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Used to close PRs that haven't gone through/been accepted the Proposal process yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants