Open yogeshtakeo opened 11 months ago
Shanti Basnet [Task 21: Context and useReducer Together] URL:https://github.com/shantibasnet/ContextApi
Name: Narayan Adhikari Task 21: Context and useReducer Together GitHub URL: https://github.com/Narayanadhikari9/context-and-useReducer-together/tree/main/Desktop/Context%20and%20useReducer
Task: State Management with Context API and useReducer in a React Application
Objective: Explore state management in a React application using the Context API and the useReducer hook.
Task Description:
In this task, you will create a React application that effectively manages state using the Context API and the useReducer hook. The objective is to understand how to centralize and handle complex application-wide state efficiently.
Exercise 1: Set Up the React Project
Exercise 2: Create Contexts
UserContext.js
andThemeContext.js
.UserContext.js
, define a context for user-related information (e.g., username, email, login status).ThemeContext.js
, define a context for managing the application's theme (e.g., light and dark themes).Exercise 3: Implement useReducer
UserContext.js
andThemeContext.js
), importuseReducer
from React.useReducer
hook and the reducer function.Exercise 4: Create Actions and Dispatch
LOGIN
,LOGOUT
,TOGGLE_THEME
,UPDATE_THEME
).dispatch
function fromuseReducer
to send actions to the reducer.Exercise 5: Implement Consumer Components
UserContext
andThemeContext
using theuseContext
hook.Exercise 6: Test and Demonstrate
useReducer
.Exercise 7: Additional Functionality (Optional)
useReducer
.Submission:
Note: The goal of this task is to demonstrate the effective use of Context API and
useReducer
for managing state within a React application. You may choose to expand this application to include more complex state management scenarios based on the objectives of your course.