How to use styled-components for AntD
styled-components
is an npm library to help overwrite CSS styling.
Note that AntD uses its own css classes to style its components. You might have noticed this if you open up AntD css with Inspect Element.
styled
from styled-components
will apply CSS styling to that component directly! It has the formatting of standard css, but with the importance level to override AntD's styles!
Heres an example of overriding the CSS of a standard AntD component: a Button
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
In general we want to only use styled
in extreme cases where our only alternative is to override AntD classes.
In the case that you want to style an AntD component to make it reusable, we could do:
1 2 3 4 5 6 7 8 9 |
|
Then import MyBetterAntDButton
where needed.
*Note that we can't do something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
I tested this and AntD classes still take priority sadly.