A comprehensive React application designed to help you learn Redux state management through practical implementation. This project demonstrates modern Redux patterns, async operations, and best practices in a real-world application.
This Contact Manager is specifically designed as a Redux learning resource that covers:
- ✅ Redux Fundamentals - Actions, Reducers, Store, and Dispatch
- ✅ Async Operations - Redux Thunk for API calls
- ✅ Modern Redux Patterns - Loading states, error handling, and optimistic updates
- ✅ Real-world Scenarios - CRUD operations with proper state management
- ✅ Best Practices - Clean code structure and separation of concerns
# Clone and install
git clone https://github.com/devmahmud/ContactManager.git
cd ContactManager
npm install
# Start learning
npm run dev// src/store.js - Redux store configuration
{
contact: {
contacts: [], // All contacts
contact: {}, // Single contact for editing
loading: false, // Loading state for async operations
error: null // Error handling
}
}// src/actions/contactActions.js
export const getContacts = () => async (dispatch) => {
dispatch({ type: 'GET_CONTACTS_START' }); // Loading starts
try {
const response = await axios.get('/users');
dispatch({ type: 'GET_CONTACTS_SUCCESS', payload: response.data });
} catch (error) {
dispatch({ type: 'GET_CONTACTS_ERROR', payload: error.message });
}
};// src/reducers/contactReducer.js
export default function (state = initialState, action) {
switch (action.type) {
case 'GET_CONTACTS_START':
return { ...state, loading: true, error: null };
case 'GET_CONTACTS_SUCCESS':
return { ...state, contacts: action.payload, loading: false };
case 'GET_CONTACTS_ERROR':
return { ...state, loading: false, error: action.payload };
default:
return state;
}
}// Using Redux in React components
import { useSelector, useDispatch } from 'react-redux';
function Contacts() {
const dispatch = useDispatch();
const { contacts, loading, error } = useSelector(state => state.contact);
useEffect(() => {
dispatch(getContacts()); // Dispatch action
}, [dispatch]);
// Component renders based on Redux state
}| Technology | Purpose | Learning Value |
|---|---|---|
| Redux 5.0.1 | State Management | Core Redux concepts and patterns |
| Redux Thunk | Async Operations | Handling API calls and side effects |
| React 18.3.1 | UI Framework | Modern React with hooks |
| React Router v6 | Navigation | Client-side routing |
| Vite | Build Tool | Modern development experience |
src/
├── store.js # Redux store configuration
├── actions/ # Action creators (async operations)
│ └── contactActions.js # CRUD operations with Redux Thunk
├── reducers/ # State reducers
│ ├── contactReducer.js # Contact state management
│ └── index.js # Root reducer
└── components/ # React components using Redux
├── contacts/ # Contact CRUD components
└── layout/ # Shared components
// Actions dispatch loading states
dispatch({ type: 'GET_CONTACTS_START' });
// Components show loading UI
{loading && <LoadingSpinner />}// Reducers handle errors
case 'GET_CONTACTS_ERROR':
return { ...state, loading: false, error: action.payload };
// Components display errors
{error && <div className="alert alert-danger">{error}</div>}// Immediate UI updates with rollback on error
case 'ADD_CONTACT_SUCCESS':
return { ...state, contacts: [action.payload, ...state.contacts] };// Redux Thunk for async actions
export const addContact = (contact) => async (dispatch) => {
dispatch({ type: 'ADD_CONTACT_START' });
try {
const response = await axios.post('/users', contact);
dispatch({ type: 'ADD_CONTACT_SUCCESS', payload: response.data });
} catch (error) {
dispatch({ type: 'ADD_CONTACT_ERROR', payload: error.message });
}
};- ✅ Create - Add new contacts with Redux state updates
- ✅ Read - Fetch and display contacts from Redux store
- ✅ Update - Edit contacts with optimistic updates
- ✅ Delete - Remove contacts with confirmation modal
- ✅ Loading States - Show spinners during async operations
- ✅ Error Handling - Display errors from Redux state
- ✅ Form Management - Controlled components with Redux
- ✅ Navigation - Route-based state management
- ✅ Redux Thunk - Async action creators
- ✅ useSelector/useDispatch - Modern React-Redux hooks
- ✅ Immutable Updates - Proper state immutability
- ✅ Action Types - Consistent action naming
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run deploy # Deploy to GitHub PagesThe application is configured for automatic deployment to GitHub Pages:
npm run deployLive Demo: https://devmahmud.github.io/ContactManager
- ✅ Automatic Build - Builds before deployment
- ✅ Client-side Routing - 404.html handles React Router
- ✅ Asset Optimization - Proper base path configuration
- ✅ Jekyll Bypass - .nojekyll file prevents Jekyll processing
Uses JSONPlaceholder API for realistic data:
- GET
/users- Fetch all contacts - POST
/users- Create new contact - PUT
/users/:id- Update contact - DELETE
/users/:id- Delete contact
- Store - Single source of truth
- Actions - Plain objects describing what happened
- Reducers - Pure functions that specify how state changes
- Dispatch - Method to trigger state changes
- Selectors - Functions to extract data from state
- Redux Thunk - Middleware for async operations
- Loading States - Managing async operation states
- Error Boundaries - Handling and displaying errors
- Optimistic Updates - Immediate UI feedback
- State Normalization - Efficient data structure
After studying this project, you'll understand:
- ✅ How to structure Redux applications
- ✅ How to handle async operations with Redux Thunk
- ✅ How to manage loading and error states
- ✅ How to integrate Redux with React components
- ✅ How to implement CRUD operations with Redux
- ✅ How to write clean, maintainable Redux code
This is a learning project! Feel free to:
- Add new Redux patterns
- Improve error handling
- Add more complex state management scenarios
- Create additional learning examples
MIT License - Feel free to use this for learning and teaching Redux!
Start your Redux journey today! 🚀
This project is designed to be a comprehensive learning resource for Redux. Each component and pattern is implemented with educational value in mind.