Skip to content

Optimize <Link>s when active-apathetic #3985

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

Closed
pshrmn opened this issue Oct 1, 2016 · 2 comments
Closed

Optimize <Link>s when active-apathetic #3985

pshrmn opened this issue Oct 1, 2016 · 2 comments

Comments

@pshrmn
Copy link
Contributor

pshrmn commented Oct 1, 2016

Now that the context.location has been removed in favor of <LocationSubscriber> I believe that it would be useful to know when not to subscribe and optimize for those situations. The only <Link> components that need to know location information are ones that care about whether or not they are active.

// care when:
// activeStyle is provided
<Link activeStyle={{color: 'blue'}} to='/foo'>Foo</Link>
// activeClassName is provided
<Link activeClassName='active' } to='/bar'>Bar</Link>
// children is a function
<Link to='/seuss'>
  {
    ({isActive, ...rest}) => (
      <a {...rest} className={isActive ? 'one fish' : 'two fish'}>
        { isActive ? 'red fish' : 'blue fish' }
      </a>
    )
  }
</Link>

// doesn't care
<Link to='/quux'>Quux</Link>

I believe that those are the only cases where location information is necessary. When none of those three cases are true, the <Link> should be able to return an <a> that is not wrapped with a <LocationSubscriber>.

@timdorr
Copy link
Member

timdorr commented Oct 1, 2016

This is coming out of this conversation: #3961 (comment)

I also agree on this. A PR would probably be best for this kind of thing.

@ryanflorence
Copy link
Member

let's continue discussion on the PR

ryanflorence pushed a commit that referenced this issue Oct 13, 2016
* Links apathetic to active don't subscribe

* add tests to check if Link subscribes
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants