Menu

Functional Components & State Management

Functional Components & State Management

A. Functional Components are JavaScript functions in React that are used to build user interfaces. They return JSX and represent independent parts of a webpage. They are simple, reusable, and form the foundation of modern React development.

In the Accordion, the entire UI is built using a Functional Component. It returns the accordion structure and keeps all logic in a single function, making the code clean, modular, and easy to manage.

B. State Management is the way React handles and stores data that can change over time. It allows the UI to respond dynamically whenever the stored values are updated. This makes applications interactive and responsive.

Here, useState controls which accordion section is open at any moment. The activeIndex state updates whenever a user interacts, and React automatically re-renders the component to reflect the correct open or closed section.