20

Is using styled-components slows down the web app more than stylesheets do?

If I care about the performance and don't have any styles that depend on props, should I just ditch styled-components and use stylesheets instead?

2 Answers 2

27

When you have lot of little components, using styled-component rendered, at the same time, the performance overhead can be meaningful. Definitely worth testing to remove styled-component on small elements.

I was using styled-component on a table cells/rows, that can generate 27260 span (cell) at once. Using React profiler, my table took around 1050-1250ms to generate, it went to 600-630ms once I remove styled component from rows and cells.

1
  • I have definitely seen the same.
    – dprothero
    Apr 6, 2021 at 21:25
14

There will always be some overhead for a runtime CSS-in-JS library since it's ultimately doing more work. But for that overhead you're also getting a lot of flexibility and power.

Every release we have improved the performance of the library, to the point where the difference is relatively imperceptible (especially when server-side rendering.)

It's entirely up to you to choose which implementation makes the most sense for your project; if all your styles are actually static, then a pure CSS approach will definitely be the most performant. But, that comes with its own caveats in terms of managing your stylesheets, writing efficient selectors, and such.

2
  • 1
    Interested to know if there is any performance implications of using it with react-native as the model to set styling rules in that platform is completely different from web
    – Hoffmann
    Feb 25, 2020 at 17:07
  • 6
    I see a difference right off the bat, switched a single component to use styled-components, and boom many headaches, lag spikes, jitters on mobile, a huge difference in performance. Demo it on a small project before you make the mistake I did. Before you ask, yes this application is optimized, compressed, etc. Its not even quicker than just writing jsx object styles.
    – twominds
    Feb 1, 2021 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.