5. Styled components #

Created Sunday 13 February 2022

Why #

How #

What #

Dependency: We need the styled-components package installed. Install it in the project using npm install --save styled-components.

Steps to use styled-components:

  1. Import styled object from the styled-components library, like so:
import styled from 'styled-components';
  1. Specify the styles for each tag inside the file. Provide a name for each tag. As the tag is already selected, there’s no need for a selector/class. Of course, pseudo-selectors can be specified, using &. Directly specify the styles for tags like so:
const Div = styled.div`
	color: red;
	background-color: salmon;

	&:hover
	{
		color: black;
	}
`

// now use <Div></Div> instead of <div></div> here.

About styled components #