Creating style object with styled components?
See original GitHub issueI’ve been researching solutions for css in js solutions and styled-components by far looks better than anything out there, love the syntax and clean approach. Only issue for out project is the concept of “creating components by styling them”, hence I wanted to see if it is possible to create style objects with styled components i.e something like following
const myStyle = ` backgroundColor: red `
<MyComponent style={myStyle} />
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
styled -components generates an actual stylesheet with classes, and attaches those classes to the DOM nodes of styled components via the className prop....
Read more >Styled Components Style Objects - Paul Scanlon
Styled Components Style Objects · Destructuring props · Decendent/Sibling selectors · Pseudo-classes · Spread operator · Unitless CSS values · With ...
Read more >How To Use Styled-Components In React - Smashing Magazine
In React's own words, styled components are “visual primitives for components”, and their goal is to give us a flexible way to style...
Read more >The Advanced Way to Style with Styled Components
This component accepts an inline style object that is then merged into the Styled Components styles by simply returning the object into the ......
Read more >Advanced ways to write styled-components - Medium
In this example, you will create the item styled component and then the unordered list styled component. Within the unordered list style, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s part of the Attrs constructor #365
I think I understand the reason you refer to in your answer, @mxstbr; you don’t want to encourage bad practices.
However, a scenario I often find myself in, is having to somehow style third-party library components using React inline style attributes. In a lot of these cases, I already have a styled-component in my library, as this is the solution I have bought into and love. Being able to somehow transform/export those style definitions to style objects for third-party library consumption would be incredibly powerful and developer-friendly.
Not sure if any of this has changed over the course of the four last years, if so please enlighten me!