What is proper way to add global css style in react component if I am using styled Component?

Viewed 1178

Right now, I figure out that I have two way to do this: One , I am putting global style such as in the App.css and then import them in the App.js

:root {
    box-sizing: border-box;

    font-size: 62.5%;
}

*,
::before,
::after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
}

Another way is to use GlobalStyles that provide by styled Component. Which way should I do ?

Thanks for the help!

1 Answers

If you using a library you should stick to its API.

Meaning using createGlobalStyle.

A helper function to generate a special StyledComponent that handles global styles.

In more advanced use cases (like having a theme) your only option to alter the global styles will be using the pre defined API.

As a side note, you can do it in more than two ways (BUT DONT DO IT), like querying the DOM and editing the style.

Related