React & Modern Frontend (445 Qs)•Part 5: React Redux State Management (101 - 134)
What is Redux?
Redux is a predictable state container for JavaScript applications, most commonly used with React. It helps you manage and centralize your application’s state in a single source of truth, enabling easier debugging, testing, and maintenance—especially in large or complex applications. Redux core is tiny library(about 2.5kB gzipped) and has no dependencies.
Practical Code Example
javascript
// Redux: Predictable state container based on 3 Core Principles:
// 1. Single Source of Truth (One global Store)
// 2. State is Read-Only (Changes happen via Actions)
// 3. Changes are made with Pure Reducer Functions:
function counterReducer(state = { count: 0 }, action) {
switch (action.type) {
case 'INCREMENT': return { count: state.count + 1 };
default: return state;
}
}