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.

Could you add in the following code where appropriate:

styled.decorator = (strings, ...values) => (Component) => styled(Component)(strings, ...values);

So that we can begin using styled-components in the following way:

@styled.decorator`
    padding: 10px;
    background: blue;
    font-size: 12px;
`
export class SomeThing extends React.Component {
    render() {
        return <div className={this.props.className}>Hello World</div>;
    }
}

It would look much cleaner than writing:

class SomeThingComponent extends React.Component {
    render() {
        return <div className={this.props.className}>Hello World</div>;
    }
}

export const SomeThing = styled(SomeThingComponent)`
    padding: 10px;
    background: blue;
    font-size: 12px;
`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
mxstbrcommented, Mar 3, 2017

I don’t think we’re going to support this officially I’m afraid, for the reasons stated above. I’m not convinced this adds any value to the library, in fact I think it takes away from the value of using it.

4reactions
kittencommented, Jun 1, 2017

It’s simply not possible and not supported, because it would allow users to easily go against or enforced best practices and methodologies.

By default we do offer passing in any component into the styled factory function, and that can be used as an escalation e hatch or even to make this possible with a helper, but it’s mainly for complex stacks of components and third party components.

It’s not recommended to use this frequently, as building up your component structures from bottom to top leads to cleaner architectures that scales. At the bottom you’ll find pure presentational components, above them structural ones, and at the top container/smart components. This can of course be nested and combined in different ways.

But by allowing this pattern by default, we’d be recommending to put the presentational components, like a stylesheet, at any position of this component stack, which is less desirable.

So if you really want to do this, we’re not stopping you. But try to keep this in mind, and we believe you’ll likely find more scalable styling code as a result.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >
THELIFESTYLEDCO™ | Full-Service Interior Design ...
THELIFESTYLEDCO™ is a full-service interior design firm and lifestyle shops based in Arizona, and rooted in our trademarked aesthetic, Organic Desert ...
Read more >
Interior Design Styles 101: The Ultimate Guide To Defining ...
Check out Decorilla's ultimate guide to decoding everything you need to know about the top 20 interior design styles for 2023!
Read more >
Style By Emily Henderson
Biggest Design Mistakes · Budget Ideas · Design Trends · Makeovers · Design Rules · Whats on My Body · How to style...
Read more >
Decorating Styles on Houzz: Tips From the Experts
Get expert advice on a wide variety of decorating styles, including modern, traditional, eclectic, coastal and rustic decor styles.
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