Benjamin Read's code garden.

Building an Accordion Component with React Hooks

Published on

This article is about: javascriptreact

In this article, we takes a deep dive into creating an accordion module for React that renders on the server, and that works in Internet Explorer 11.

On a recent project I was involved in creating this Accordion component with a few key requirements:

Let’s get started!

Basic Setup #

Here’s the basic layout for the module:

import React from "react"
const Accordion = (props) => {
  return (
    <li>
      <h3>
        <button>
          {question}
        </button>
      </h3>
      <div>
      {answer}
      </div>
    </li>
  )
}
export default Accordion

This will render a basic section and can accept our content labelled question and answer. Outside the accordion, I will define an unordered list, 

Read more articles about: javascriptreact

Comments

No comments yet. Be the first to comment!


“Wisest are they who know they do not know.”

— Jostein Gaarder