-
Notifications
You must be signed in to change notification settings - Fork 429
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] What is a good way to share state between routes? #163
Comments
can you provide a more concrete example with code? |
@sibelius hey, thanks for waiting so long 😰 More concretely put: In the issue-tracker example. Let's say you select an issue, then this issue will be opened in a new detail view and the data is preloaded with a new query belonging to a route. However, that also means that the state, which is an id in this case, must be stored in the url bar, so that the route that is navigated to can access that state to figure out what to render in detail view. So my question then becomes, let us say you that you would like to use some state to preload a query but you don't want to put the state in the URL as part of the route, how would you do that? |
what kind of state? |
Selected item id from a list of items |
it is still not clear, you could save this on a context, or client schema extension (https://relay.dev/docs/en/local-state-management), or Recoil, or using react router history state |
For the suggestions apart from react router history state, how would you access these values in the preloadedQuery? For the react router history state the example is fine because params is accessible from the prepare function. That function doesn't have access to context. |
can you provide a code example of this? |
https://github.com/relayjs/relay-examples/blob/master/issue-tracker/src/routes.js#L73 Take routes.js:73 as an example, how can you get state inside of the prepare function without storing it in react router history state? |
you need to consume some "global" data from it |
What are the best practices?
For instance, you'd often have multiple routes with each of their query, which in turn makes it hard to share fragment pointers. How do you recommend to share data such as currentUser and other types of state between components?
The text was updated successfully, but these errors were encountered: