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.

How to style react.router.dom.Link with styled components?

See original GitHub issue

Tried the following ways:

  1. Manual introduction of a CSS class -> no dynamic CSS configurations are possible:
Link {
        attrs {
            className = ClassName("SomeClassName")
            // ...
        }
        // ...
}
  1. Raw style description -> mixing with rule sets and pseudo-classes usages are not possible:
Link {
        attrs {
            style = CssBuilder().apply {
                visited {
                    color = Theme.palette.actionSecondary1.get(context)
                }
                // ...
            }.toStyle().unsafeCast<Properties>()
        }
        // ...
}
  1. css { ... } blocks inside of Link -> attrs obviously don’t work as well.

Is there any convenient solution to style react.router.dom.Link dynamically with styled components?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andrew-k-21-12commented, Apr 21, 2022

And as it was expected, it can be also done pretty easily with styled components:

div { // can be any other RDOMBuilder scope provider
    styled(Link).invoke(this) { // "this" refers to the current RDOMBuilder, i.e. where to insert this component
        css {
            // Required styling.
        }
        attrs {
            to = "setting-attributes"
        }
        +"Link's label"
    }
}
0reactions
andrew-k-21-12commented, Apr 6, 2022

If there are no ways to do the described thing via styled components - then yes, sure, will switch to kotlin-emotion 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to style your React-Router links using styled-components
METHOD-3: Styling React-Router links using 'NavLinks' and 'activeClassNames'. ... Solution : Using NavLink, we can save time by not writing any ...
Read more >
Styling react-router-dom Link using styled-components getting ...
I pass props to my styled-components all the time. I don't know if the problem is that I'm styling a component Link instead...
Read more >
Basic implementation of React router and styled-components
Basic implementation of React router and styled-components. Contains a extreme small setup for react-router 4.1.2. Also implements Styled Components for ...
Read more >
Basics - styled-components
The styled method works perfectly on all of your own or any third-party component, as long as they attach the passed className prop...
Read more >
Style active state of Links in Styled Components - Medium
Handling ActiveClassName with React Router. The activeClassName property is used to give a CSS class to an element when it is active. ·.attrs...
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