InterviewHubPRO
Section Overview
Q103

Question 103 of 445

Part 5: React Redux State Management (101 - 134)

23%
React & Modern Frontend (445 Qs)•Part 5: React Redux State Management (101 - 134)

What are the core principles of Redux?

Redux follows three fundamental principles:

  1. Single source of truth: The state of your whole application is stored in an object tree within a single store. The single state tree makes it easier to keep track of changes over time and debug or inspect the application.
jsx
const store = createStore(reducer);
  1. State is read-only: The only way to change the state is to emit an action, an object describing what happened. This ensures that neither the views nor the network callbacks will ever write directly to the state.
js
const action = { type: 'INCREMENT' };
store.dispatch(action);
  1. Changes are made with pure functions(Reducers): To specify how the state tree is transformed by actions, you write reducers. Reducers are just pure functions that take the previous state and an action as parameters, and return the next state.
jsx
function counter(state = 0, action) {
 switch (action.type) {
   case 'INCREMENT':
     return state + 1;
   case 'DECREMENT':
     return state - 1;
   default:
     return state;
 }
}