Skip to content
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

Add support for function to #3669

Merged
merged 1 commit into from
Jul 26, 2016
Merged

Add support for function to #3669

merged 1 commit into from
Jul 26, 2016

Conversation

taion
Copy link
Contributor

@taion taion commented Jul 25, 2016

Closes #3657

I'm not absolutely sure this is entirely correct – the "nice" way to use this requires creating a throwaway function in render. But <Link> isn't a pure component right now anyway.

@taion
Copy link
Contributor Author

taion commented Jul 26, 2016

Rebased.

@@ -22,6 +22,10 @@ function isEmptyObject(object) {
return true
}

function resolveToLocation(to, router) {
Copy link
Member

Choose a reason for hiding this comment

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

I would make this a class method so you don't have to pass it any args Bonus points: You can make it a getter (router.push(this.to)).

Also, and this is personal preference, but I'm generally not a fan of extracting methods from a class unless they are also being exported from the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't a class method because we need to strip out to from props in render anyway – we can't (shouldn't) pass it down because otherwise we get React 15.2.x "unknown props" warnings.

The other options would be to either destructure it out and leave it unused, or do an explicit delete, both of which are uglier than just using it as a function arg.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, we're still using createClass, so that's not even possible. I meant something like this:

get to() {
  const { to } = this.props
  return typeof to === 'function' ? to(this.context.router.location) : to
}

handleClick(event) {
  //...
  router.push(this.to)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this just ends up being the cleanest way to strip off the to prop before it gets to the underlying <a>.

@timdorr timdorr merged commit f676dcb into next Jul 26, 2016
@timdorr timdorr deleted the function-to branch July 26, 2016 21:05
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants