Skip to content
Shubham JangleResources
React

Explore topics

Components and Styling

Watch the walkthrough
Open on Instagram

Quick revision

A component packages markup and behavior behind a reusable interface. Use a capitalized name such as Navbar; lowercase tags refer to browser elements. Define component functions at module scope so their identity stays stable between renders.

JSX and styling

  • Close every tag, including <img /> and <input />.
  • Use a parent element or Fragment when returning adjacent elements.
  • Write className, htmlFor, and camelCase style properties. aria-* and data-* retain their hyphens.
  • An inline style is an object: style={{ backgroundColor: "orange" }}.
  • Use CSS classes for shared appearance; use inline values for styles driven by runtime data.

Follow the repository example

App composes Navbar and ProductList. The products demonstrate inline styles, an ID selector, and a class selector. Prefer reusable classes over IDs for repeated cards. CSS does not become component-scoped merely because it was imported into a component.

Recall check

Extract a Product component that accepts its label through props. A reusable component should express a meaningful UI responsibility, rather than split every individual tag into a separate file.

Reference: Writing markup with JSX.

Supporting material