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

documentation inaccurate for props.location #3540

Closed
brennancheung opened this issue Jun 14, 2016 · 4 comments
Closed

documentation inaccurate for props.location #3540

brennancheung opened this issue Jun 14, 2016 · 4 comments

Comments

@brennancheung
Copy link

According to the documentation if I want to access props.location it tells me I should add it to the context.

Access location from this.props.location of your Route component. If you'd like to get it deeper in the tree, you can use whatever conventions your app has for getting props from high down low. One option is to provide it on context yourself

When I do this it tells me:

context.location is deprecated, please use a route component's props.location instead. http://tiny.cc/router-accessinglocation

But it doesn't have props.location. Which is the whole reason I added it to the context.

I tried adding withRouter because the documentation states:

NOTE: v2.4.0 and higher include a higher-order component withRouter that is now the (highly) recommended way of accessing the router object.

But I don't see any way to get access to location from the router object and withRouter doesn't add props.location to the wrapped component.

What is the recommended approach to accessing location when not a top level route component? This should be documented.

@brennancheung
Copy link
Author

brennancheung commented Jun 14, 2016

I'm seeing that there was a PR (#3444) that adds props.location when you use withRouter but it is not yet available.

The latest in npm is 2.4.1 and the documentation is very confusing and provides no path forward. It tells you to use context, and then when you do, it tells you not to use context. lol

Should the documentation be updated telling people to use 3.0 alpha and check it out from github instead of npm? What's the best route forward?

Another possibility is updating npm to have a version that includes #3444.

@taion
Copy link
Contributor

taion commented Jun 14, 2016

  1. The recommendation is to put location on context yourself, not use the deprecated built-in one
  2. That code is released on the v3 alpha

@taion taion closed this as completed Jun 14, 2016
@brennancheung
Copy link
Author

Maybe I'm missing something. Not sure what you mean by the deprecated built-in one. There is no context.location by default. I added it to the context myself from a route component and then pulled in the context with a child component. When I do that I see the deprecation warning telling me not to use context.location. If that is the recommended route, then why is it telling me not to do that?

@taion
Copy link
Contributor

taion commented Jun 14, 2016

You are not correctly exporting location on context, then. That deprecation warning only shows up if you're somehow hitting the deprecated export of context.

@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants