PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

React · Theory

Carousel in React

← All stacks

Theory

62/94

Carousel in React

Carousel = array of slides + index state. Next: setI(i => (i + 1) % n). Prev similar. Optional autoplay is useEffect + interval + cleanup. Accessibility: buttons labelled, pause on focus. Libraries exist; a 10-line version proves you understand state.

Carousel in React — start A. Next → B. Modulo wraps to A after C.

Exam tip

Index state + modulo next.

Example

// Carousel
import { useState } from "react";

const slides = ["A", "B", "C"];

export default function Carousel() {
  const [i, setI] = useState(0);
  return (
    <div>
      <p>{slides[i]}</p>
      <button onClick={() => setI((x) => (x + 1) % slides.length)}>Next</button>
    </div>
  );
}

Carousel in React — start A. Next → B. Modulo wraps to A after C.

Short notes

  • DefState : index.
  • RuleNext : modulo wrap.
  • RememberAutoplay : effect + cleanup.

Questions

1

Explain Carousel as if you are teaching a junior — definition, then one tiny UI.

2

Write 5–10 lines that use Carousel and say what the UI does.

3

What mistake do freshers make with Carousel?

Previous← Unit Testing in ReactNextPagination in React →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.