Managing highly dynamic styles
See original GitHub issueExample component:
const Comp = styled.div`
/*lots of styles here*/
animation-delay: ${ props => props.index * 0.1 };
`;
With this component rendered over a collection of items, we’ll generate a new style tag with an associated class for each one.
Is there a recommended way of working with these kinds of styles so as not to thrash the head with a new style
tag everytime render
is called on Comp
?
- One solution could be to move the
/* lots of styles here */
into another component that doesn’t include the dynamic properties that cause huge amounts of CSS to be rendered into thehead
. This way the generatedstyle
tag only contains theanimation-delay
property. Still a lot ofstyle
tags being injected into the head though and since the injection only happens at render time, this could cause some trashing. - Another option is to put the
animationDelay
into thestyle
prop of the component as we compose the components and not let styled-components handle this.
How would you do this? Is there a recommended approach?
I saw there might be some plans to extract static styles which, as a solution, is similar to our first option above.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:13
- Comments:42 (27 by maintainers)
Top Results From Across the Web
Dynamic management: Better decisions in uncertain times
My sense, though, is that achieving truly dynamic management will prove elusive for most organizations until they can figure out how to get ......
Read more >High Performance Dynamic Styles - Medium
Inline Styles have a number of limitations by design: 1. You can't share an inline style declaration between multiple elements. 2. You need...
Read more >How To Achieve Dynamic Leadership In 'The New Next' - Forbes
Dynamic leaders understand that we no longer live in a static world. They chose to focus on only one thing at a time....
Read more >The Dynamics of 8 Different Styles of Leadership | ATD
Insights Into 8 Leadership Styles · Pacesetting, Autocratic Style · Democratic, Participative Style · People-Focused, Affiliative Style.
Read more >9 types of management styles and when to use them - Asana
Best for: Managers that are leading a more inexperienced team. Under this dynamic, the manager should be the sole decision-maker based on their ......
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
I’ll finally close this discussion since a lot of things have changed since the initial kickoff by @JamieDixon. (thanks!)
.attrs
selector, making dynamic styles that come in via props possible with inline styles. You could change thebg
prop of this component a lot of times without running into performance issues. (I’d be interested to see the color picker from above reworked this way though!)That should clear up most, if not all concerns around highly dynamic styles and styled-components. If you have further issues, suggestions or comments please feel free to open a new issue with your ideas!
@mxstbr Better late than never!
It works beautifully. Thanks for the great work everyone. SC has made such a difference to our project.