-
Notifications
You must be signed in to change notification settings - Fork 842
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 Context component to enable single point of integration with react-router #814
Comments
Idea pulled from PR #810 into it's own issue |
@cjcenizal responding to your comment on #810, this is indeed what I was starting to suggest. Comparing the two approaches: Idea 1From #810 , something inline that generates an <Adapter to="/location">
{(props) => (
<EuiLink {...props}>click here</EuiLink>
)}
</Adapter> pros
cons
Idea 2Provide a navigation handler via React context and make <EUIProjectContext options={{
onNavigation={href => this.props.history.push(href)}
}}>
<EuiLink href="http://www.elastic.co">
Elastic website
</EuiLink>
</EUIProjectContext> pros
cons
|
With those pros/cons in mind I lean toward CJ's original idea without |
Some feedback on your pro/con list For the one con of “potential to not realize they don’t have context” I would say this is perhaps not a bad thing? I mean it would be easy to debug the lack of the parent context. As for sane fallback, if we just call the context method if it exists, sane fallback would just be to not call it. Works the same as now. The indirection is perhaps the biggest con here imho and I agree completely that it is... non-ideal |
Easy to debug, but how difficult to notice you need to (honest question, I don't have a good answer)?
Totally! Simple in this case, but it does add more logic to the component. One thought I just had - can plugins (now or in the future) inject links in places?
|
I would say easy. if you add a page, and the link reloads your screen, then you need the context component. I think a simple note in the docs would suffice for this. But perhaps thats just me? Would love feedback on that from others.
"Inject links" no, support for linking between plugins I think is something that is desired AFAIK but not via injection. for external links, yes RR does not really support them, I have always just used |
@jen-huang @nreese @pugnascotia any thoughts / feedback on usability around this vs. the approach in #810 ? (see OP & first comment on this thread for context/overview). |
I don't really understand what we're talking about here. What problem are we trying to solve exactly? Is it being able to translate a named route within a routing library to the actual url for use with EUILinks? |
Wanting to connect The two approaches solve this by 1. explicitly wrapping |
We've just been doing |
@chandlerprall and I chatted offline about this and I'll offer my two cents. I don't think adding an abstraction for handling programmatic routing adds much if any value. I honestly don't know any other react routing libraries other than react-router but I imagine each one provides a way to handle programmatic routing that works in all React environments. For react-router@v4, the most straight-forward approach is to wrap the component in the I'm doing this in my current project: This feels natural to me as I'm relying on the specific routing library I'm using to handle the navigation and if I come in new to the project with experience of react-router, I'd expect to see this and it would make sense. If we add an abstraction on top of this to handle all routing libraries, or avoid having to wrap with a HoC, it's going to make it harder to go from understanding how the routing library handles it to how EUI handles it. Maybe I'm alone, but I don't see any reason to adjust my current approach for handling routing but I can be convinced otherwise :) |
@chrisronline Thanks for sharing your experience and the links to your implementation. I think it's really valuable to have a real use case added to the discussion and I think the way you're doing things is fine.
I think this is a great point, and it adds more weight to going with Idea 1 above, which won't actually be added as code to EUI but will instead be provided as guidance in our documentation (#810). We could also document an alternative approach modeled after how you're doing things, though I'm guessing react-router's documentation already covers this approach since it looks pretty idiomatic. |
@chrisronline You make some excellent points. At this point I am fine with closing this in favor of idea 1 |
Closing this, moving back to #810. Thanks everyone! |
Do something like:
EuiLink and other linkable components could then just call onNavigation from context if it exists.
This way:
The text was updated successfully, but these errors were encountered: