Extend the mini e-commerce application by introducing React Context API to manage a shared budget mode, allowing users to filter products based on their price.
| Repository | Project | Category | Main Focus | Exercise |
|---|---|---|---|---|
| react-context-api | React Context API | Exercise | React Context, dynamic filtering | 40/50 |
Implement a shared context to manage the application's budget mode and control which products are displayed in the store.
Create a new context called BudgetContext.
- Add a boolean state called
budgetMode(true/false). - Provide the
setBudgetModefunction to update its value. - Wrap the entire application with the
BudgetProvider.
Create a Navbar.jsx component if one does not already exist.
- Add the Navbar to
App.jsxor to the existing layout component. - Include a Budget Mode button that toggles
budgetModewhen clicked. - Dynamically update the button label depending on the current state:
Activate Budget ModeDeactivate Budget Mode
Modify the Products page to use the shared context.
- Retrieve the
budgetModevalue fromBudgetContext. - When
budgetModeistrue, display only products withprice <= 30. - Otherwise, display all products normally.
Turn budget mode into a configurable price filter.
- Add a numeric
maxPricevalue to the context, with an initial value ofnull. - Add a number input field to the Navbar, connected to the
maxPricevalue in the context. - In the Products page, display only products with
price <= maxPrice.
Important: If maxPrice is null or budgetMode is inactive, display all products, without applying the price filter.
- Creating and managing React Context.
- Sharing state across multiple components.
- Implementing a Context Provider.
- Accessing shared state with
useContext. - Managing boolean states and toggle functionality.
- Building dynamic filters based on product prices.
- Connecting form inputs to shared context values.
- Combining application state with conditional rendering.
Exercise assigned by Boolean Tech Academy as part of the Web Development course (Class 152, A.Y. 2025-2026).