question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure "Link" component via Theme

See original GitHub issue

Some components (like Buttons) might end up rendering a tags. That’s ok, but in usually you cannot use “links” in SPA - they have to be Links, playing nicely with the router of your choice.

It’s expected that SPA is using some router, and only one router, as well as expected to use one, and only one Link. That “right link” should be configurable via Theme.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Long story short - for example button should read value from the theme, not use hardcoded one.

https://github.com/mui-org/material-ui/blob/49eb56aefa997dcbf6fbc0515b7d1fafc19a55dd/packages/material-ui/src/ButtonBase/ButtonBase.js#L264-L266

Examples 🌈

  • no example provided

Motivation 🔦

Every component which might render a link could do it - all you have to provide a right Component instead of default. That’s not always handy and working for everyone.

Recently I’ve seen:

  • Buttons wrapped with Links to make them Links
  • Buttons with onClick={()=>history.push()} to make them play nicely together with router.

All that might be fixed with a single configuration option.

It still would be not possible to use, for example, react-router/Link as a link, due to interface differences, however the wrapper to make Link an a-compatible is just a few lines, and could be provided in MUI documentation as well.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
sheerryycommented, Jun 24, 2020

Can I take this issue?

1reaction
oliviertassinaricommented, Jun 22, 2020

Yeah, in this case, the diff in https://github.com/mui-org/material-ui/issues/21533#issuecomment-647411584 would be interesting. We could use it for Gatsby too cc @hupe1980.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure "Link" component via Theme · Issue #21533 - GitHub
It's expected that SPA is using some router, and only one router, as well as expected to use one, and only one Link....
Read more >
Theme UI react router link with typescript - ReactJunkie
In this post I'll describe how you can create a theme-ui aware Link component with react router or gatsby in typescript.
Read more >
Theming and Theme Switching with React and styled ...
Define a theme (i.e. background color, font color, buttons, links, etc.) Create and save multiple themes; Select and apply a theme; Switch ...
Read more >
3 Ways To Theme React Components - Bits and Pieces
Two ways to theme React components using CSS custom properties. ... The css-variable is the name of the CSS variable and value is...
Read more >
How to style React Router links with styled-components
Adding and styling navbar links using styled-components. Inside our src folder, create a folder called styles and a file named NavStyle .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found