FT
FAQ Templates

GUIDE_LOG // REACT_GUIDE

React FAQ components

React is useful when FAQ content needs controlled disclosure state, filtering, or reuse across product surfaces.

React FAQ Components: Interactive and Reusable

React allows us to turn static FAQ sections into dynamic, stateful components that can be easily reused across multiple pages or projects.

Benefits of React for FAQs

A Simple Accordion Component

A basic React accordion uses the useState hook to manage the active index.

import { useState } from "react";

interface FaqItem {
  id: string;
  question: string;
  answer: string;
}

export function Accordion({ items }: { items: FaqItem[] }) {
  const [openIndex, setOpenIndex] = useState<number | null>(null);

  return (
    <div className="space-y-4">
      {items.map((item, index) => {
        const triggerId = `faq-trigger-${item.id}`;
        const panelId = `faq-panel-${item.id}`;
        const isOpen = openIndex === index;

        return (
          <div key={item.id} className="border rounded-lg overflow-hidden">
            <button
              id={triggerId}
              className="w-full text-left p-4 font-bold bg-gray-50 hover:bg-gray-100 transition-colors"
              onClick={() => setOpenIndex(isOpen ? null : index)}
              aria-expanded={isOpen}
              aria-controls={panelId}
            >
              {item.question}
            </button>
            {isOpen && (
              <div
                id={panelId}
                role="region"
                aria-labelledby={triggerId}
                className="p-4 border-t text-gray-600"
              >
                {item.answer}
              </div>
            )}
          </div>
        );
      })}
    </div>
  );
}

Adding Search Functionality

For large FAQs, adding a client-side search filter significantly improves the user experience.

const [query, setQuery] = useState("");
const filteredItems = items.filter((item) =>
  item.question.toLowerCase().includes(query.toLowerCase()),
);

return (
  <>
    <label htmlFor="faq-search">Search questions</label>
    <input
      id="faq-search"
      type="search"
      value={query}
      onChange={(event) => setQuery(event.target.value)}
    />
    <p aria-live="polite">{filteredItems.length} results</p>
    {filteredItems.map((item) => (
      <article key={item.id}>
        <h3>{item.question}</h3>
        <p>{item.answer}</p>
      </article>
    ))}
  </>
);

Accessibility with ARIA

React makes it easy to manage ARIA attributes dynamically. Ensure you use:

Animation Options

Start with CSS transitions on opacity or grid rows. Keep the answer available to assistive technology only when it is visually open, and respect prefers-reduced-motion.

Best Practices

  1. Unique Keys: Always use a unique identifier (like an ID or a slug) for the key prop, rather than the array index if the list can change.
  2. Memoization: If you have a very long list of FAQs, use useMemo for your filtering logic.
  3. Default States: Decide if you want all items closed by default, or the first one open to guide the user.

Conclusion

React allows for the creation of interactive and accessible FAQ components. By leveraging hooks and props, you can create a flexible system that adapts to your application's requirements.

BACK_TO_CATALOG

Templates_in_React

ASSET_ID: MINIMAL_ACCORDION

Minimal Accordion

A quiet, accessible disclosure pattern for product and documentation pages.

html · tailwind · react

ASSET_ID: ANIMATED_ACCORDION

Animated Accordion

A smooth, interactive accordion with elegant slide transitions and rotating icons.

html · tailwind · react

ASSET_ID: TWO_COLUMN_FAQ

Two-column FAQ

A scannable FAQ layout for landing pages with short, independent answers.

tailwind · react

ASSET_ID: CATEGORIZED_FAQ

Categorized FAQ

Organize large sets of questions into logical groups for better discoverability.

html · tailwind · react

ASSET_ID: SEARCHABLE_FAQ

Searchable FAQ

A powerful FAQ interface with a real-time search filter to help users find answers instantly.

tailwind · react

ASSET_ID: CONTACT_FALLBACK_FAQ

FAQ with Contact Fallback

A standard FAQ layout paired with a prominent 'Contact Us' call-to-action for unresolved queries.

html · tailwind · react

ASSET_ID: DARK_MODE_ACCORDION

Dark Mode Accordion

A visually striking accordion designed specifically for dark-themed interfaces and high-contrast environments.

tailwind · react

ASSET_ID: PRICING_FAQ

Pricing & Billing FAQ

A grid-based FAQ specifically tailored for handling billing, subscription, and pricing questions.

tailwind · react

ASSET_ID: PRODUCT_ONBOARDING_FAQ

Product Onboarding FAQ

A card-based FAQ layout designed to guide new users through their first steps and common setup hurdles.

tailwind · react

ASSET_ID: COMPACT_INLINE_FAQ

Compact Inline FAQ

A minimalist, space-saving FAQ design for sidebars or mid-article content.

html · tailwind · react