Menu

Event Handling & Conditional Rendering

Event Handling & Conditional Rendering

A. Event Handling refers to responding to user actions such as clicks, input events, or mouse movements. It connects user interactions with specific functions that control application behaviour.

Each accordion header uses an onClick event to trigger the toggle function. When a user clicks, it decides whether to open a new section or close the current one based on the selected index.

B. Conditional Rendering means showing or hiding elements based on certain conditions. It allows React to control what appears on the screen depending on the current state.

The visibility of each accordion content depends on the activeIndex value. When a section is active, its content is displayed; otherwise, it remains hidden, creating a smooth expand-and-collapse effect.