Skip to main content
InterviewHubPRO
Section Overview
Q150

Question 150 of 407

Part 7: Supported Libraries, Styling & Integrations (139 - 151)

37%
React Core & Hooks (407 Qs)•Part 7: Supported Libraries, Styling & Integrations (139 - 151)

Give an example of Styled Components?

mid LevelCode ExampleComponents

Lets create <Title> and <Wrapper> components with specific styles for each.

javascript
import React from "react";
import styled from "styled-components";

// Create a <Title> component that renders an <h1> which is centered, purple, and responsive
const Title = styled.h1`
  font-size: 1.5rem;
  text-align: center;
  color: #7c3aed;
`;

// Create a <Wrapper> component that renders a section with background and padding
const Wrapper = styled.section`
  padding: 2rem;
  background: #f8fafc;
  border-radius: 12px;
`;

export default function StyledApp() {
  return (
    <Wrapper>
      <Title>Hello Styled Components!</Title>
    </Wrapper>
  );
}