Using Basic Styled-components in ReactJS

Tram Ho

What are styled-components?

Styled-component is a great CSS-in-JS library for ReactJS. It helps you to customize and manage your CSS code easily.

Install Styled-components as follows:

Basic styled-components

Creating a component using styled-components

Props

You can also pass props through a component like React to customize the CSS.

Another example for passing props.

Extending Styles

Is an easy way to create a new component that inherits the styles of the old component.

Styling any component

This feature makes it possible for us to CSS for any component such as Link in React-router-dom.

CSS Selector

In Styled-components you can use basic CSS selectors like > , + , ~ …

And use Nesting like SASS

Animations

How to use Styled-component in React?

Conclude

Above are the basic features of Styled-components. Although basic, it is enough for you to apply it to ReactJS.

Stay tuned for part 2 with features like theme, global, css. Thank you for reading the article.

Share the news now