Using CSS-in-JS with Preact
The two most popular CSS-in-JS libraries, styled-components and Emotion, don’t support Preact out of the box. However there is an easy workaround.
Add these aliases to your webpack.config.js
file:
Adding these aliases allows you to use other libraries intended for React too!
And if you’re using Storybook, you’ll need to add the same alias to your .storybook/main.js
file:
After this you can install your preferred package:
And use either styled-components or Emotion without any problems:
Comments