Skip to content

Page table of contents in React

A table of contents that follows the reader through a long article and highlights the current section.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

PageToc.tsx
import { useEffect, useState } from "react";

const sections = [
  {
    id: "emplacement",
    title: "Choisir l'emplacement du rucher",
    paragraphs: [
      "Installez vos ruches dans un endroit abrité du vent dominant, avec l'entrée orientée vers le sud-est pour que le soleil du matin réveille la colonie tôt. Un léger ombrage l'après-midi évite la surchauffe en plein été.",
      "Prévoyez un point d'eau à proximité et vérifiez les distances imposées par l'arrêté préfectoral de votre département vis-à-vis des habitations et des voies publiques. Toute ruche doit aussi être déclarée chaque année, dès la première colonie.",
    ],
  },
  {

Free component: copy it freely, including for commercial projects.

Breadcrumbs and pagination components in React
  • A bottom bar with Call, Directions and Free quote that tucks away while visitors read down the page and returns as soon as they scroll up. Built for tradespeople whose customers arrive on a phone.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A slim bar at the top of the page with a message, a link and a close button; once closed, it stays hidden for the period you choose.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A sticky sidebar table of contents for blog posts: it highlights the section being read, shows the reading time left and folds into a list under the title on mobile.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A column of dots on the side of the page that follows the section being read and lets visitors jump to it, with a label on hover and focus.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An order step indicator: finished steps clickable to go back, the current step announced, upcoming steps locked.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Tooltips in four positions that open on hover, tap and keyboard focus, and close with Escape, as WCAG requires.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component