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.

Format styled.div(({theme}) => `...`

See original GitHub issue

People often write this kind of code:

const StyledDiv = styled.div`
    color: ${props => props.theme.primary.main};
    background-color: ${props => props.theme.backgroundColor};
    border: 1px solid ${props => props.theme.borderColor};
    ...
`

But, there is an underrated way of writing this code, that makes it much clearer:

const StyledDiv = styled.div(({theme}) => `
    color: ${theme.primary.main};
    background-color: ${theme.backgroundColor};
    border: 1px solid ${theme.borderColor};
    ...
`)

However, the VSCode plugin doesn’t style the latter. Would it be possible to style it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:8

github_iconTop GitHub Comments

3reactions
nhagencommented, Nov 5, 2019

Not ideal, but you can do this as a workaround:

const StyledDiv = styled.div(({ backgroundColor }) => css`
    backgroundColor: ${ backgroundColor }
    ...
  `);
0reactions
jasonwilliamscommented, Nov 8, 2020

There’s links to websites in the contributing guide @a7madgamal

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basics - styled-components
div), styled-components passes through any known HTML attribute to the DOM. If it is a custom React component (e.g. styled(MyComponent)), styled-components ...
Read more >
styled() - MUI System
Utility for creating styled components. ... This utility is built on top of the styled() module of @mui/styled-engine and provides ... Styled div...
Read more >
Styled Components, Styled Systems and How They Work
Template Literals are clean, they're effective and they have been so well ... styled.div` color: ${( props ) => props.theme.color.primary} ...
Read more >
Theming in React with Styled Components | by Ross Bulat
apply theming to a styled componentconst Wrapper = styled.div` ... props to pass theme styles through the <ThemeProvider /> , in the form...
Read more >
Complete Guide On How To Use Styled-components In React
I have often found styling a React application very confusing and ... const Example6 = () => { return ( <div> <h2>Fill the...
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