Skip to content

Practice question showing question of previous catagory #34

@MuganSama

Description

@MuganSama

Bug Report

Building: School House
Difficulty (your estimate): Easy

What is broken?

In the practice section, selecting a new category tab displays questions from the previously selected category instead of the newly selected one.

Steps to reproduce

  1. Go to the School House (Practice section).
  2. Click on any category tab (e.g., Category A).
  3. Click on a different category tab (e.g., Category B).
  4. Observe that the questions displayed belong to Category A, not Category B.

Expected behavior

The question list should immediately update to fetch and display questions from the currently clicked category.

Actual behavior

The UI renders questions from the previously viewed category. No console errors are thrown; it is a logical state bug that trails one step behind the user's clicks.

Root cause

React state updates are queued and do not process immediately. The original code used the current, soon-to-be-stale state variable (activeCategory) to update the question category. Because the component hadn't re-rendered yet, it passed the old category value into the question fetcher.

Fix

Updated the function to bypass the stale state and pass the incoming argument directly.
Changed setQuestionCategory(activeCategory) to setQuestionCategory(nextCategory).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions