
A simple, interactive React application that demonstrates the core concepts of React through an Accordion UI—a set of questions with toggleable answers. This project is ideal for learners looking to strengthen their understanding of React state management and component structure.
- Live-Demo: https://accordion-arnob.netlify.app/
- Project Summary
- Features
- Technology Stack
- Project Structure
- Component Overview
- How It Works
- Getting Started
- Code Walkthrough & Examples
- Learning Outcomes & Keywords
- Conclusion
This project is designed as a fundamental React exercise, focusing on the creation of a dynamic Accordion (FAQs/questions) interface. It covers essential React concepts such as functional components, props, state management using useState
, conditional rendering, and iterating over data. Through this project, learners can see how to structure a small React app and manage UI interactions efficiently.
- Lists questions and allows toggling their answers (Accordion behavior).
- Only one answer visible at a time (if implemented as a challenge).
- Uses React functional components and hooks (
useState
). - Clean and modular code structure.
- Styled with modern CSS.
- React (v18+): UI library for building component-based interfaces.
- Vite: Fast development server and build tool.
- JavaScript (ES6+)
- CSS: For styling.
- react-icons: For toggle icons (+, -).
Accordion--React-Fundamental-Project-4/
│
├── src/
│ ├── App.jsx # Main app component
│ ├── Questions.jsx # Renders list of questions
│ ├── SingleQuestion.jsx # Component for each question
│ ├── data.js # Questions data array
│ ├── index.css # App styling
│ └── main.jsx # React app entry point
│
├── public/
│ └── index.html # Main HTML file
│
├── package.json # Project dependencies and scripts
├── vite.config.js # Vite config
└── README.md # Project documentation
- Imports data and manages the
questions
state. - Renders the
Questions
component.
- Receives the
questions
prop. - Maps each question to a
SingleQuestion
component.
- Handles the toggle state (
showInfo
) for showing/hiding answers. - Displays question title, and toggles icon (+/-) and answer.
- Exports an array of question objects:
{ id: 1, title: 'Do I have to allow the use of cookies?', info: 'Unicorn vinyl poutine brooklyn, ...' }
- Data Import: The questions are defined in
data.js
as an array of objects. - State Setup:
questions
state is initialized inApp.jsx
usinguseState(data)
. - Rendering:
Questions.jsx
receives the questions and renders aSingleQuestion
for each. - Toggle Functionality: Inside each
SingleQuestion
, a local state (showInfo
) manages answer visibility. Clicking the button toggles the state, either showing or hiding the answer. - Icons: Uses
react-icons
for the toggle button (+ for expand, - for collapse). - Styling: Styles are applied via
index.css
for a polished UI.
- Node.js (v16+ recommended)
- npm
-
Clone the repository:
git clone https://github.com/arnobt78/Accordion--React-Fundamental-Project-4.git cd Accordion--React-Fundamental-Project-4
-
Install dependencies:
npm install
-
Run the development server:
npm run dev
The app will be available at
http://localhost:5173
by default.
import { useState } from 'react';
import data from './data';
import Questions from './Questions';
function App() {
const [questions, setQuestions] = useState(data);
return (
<main>
<Questions questions={questions} />
</main>
);
}
export default App;
const questions = [
{
id: 1,
title: 'Do I have to allow the use of cookies?',
info: 'Unicorn vinyl poutine brooklyn, next level direct trade iceland...',
},
// ...more questions
];
export default questions;
import SingleQuestion from './SingleQuestion';
const Questions = ({ questions }) => {
return (
<section className='container'>
<h1>Questions</h1>
{questions.map((question) => (
<SingleQuestion key={question.id} {...question} />
))}
</section>
);
};
export default Questions;
import React, { useState } from 'react';
import { AiOutlineMinus, AiOutlinePlus } from 'react-icons/ai';
const SingleQuestion = ({ title, info }) => {
const [showInfo, setShowInfo] = useState(false);
return (
<article className='question'>
<header>
<h5>{title}</h5>
<button
className='question-btn'
onClick={() => setShowInfo(!showInfo)}
>
{showInfo ? <AiOutlineMinus /> : <AiOutlinePlus />}
</button>
</header>
{showInfo && <p>{info}</p>}
</article>
);
};
export default SingleQuestion;
The CSS uses modern CSS variables for color schemes, box shadows, and layouts to create a visually appealing and responsive design.
- React Functional Components
- useState Hook
- Props and Data Passing
- Conditional Rendering
- Component Composition
- Event Handling
- React Icons Integration
- Project Structure and Organization
- Iterating Over Data
This Accordion project is a concise yet powerful demonstration of React fundamentals. It encourages understanding of how to work with state, props, and component-driven design, making it an excellent learning resource for beginners. The modular and well-commented codebase, coupled with modern tooling (Vite, React, ES6+), makes it easy to extend or use as a base for more complex projects.
For more details and code, visit the GitHub repository.