Redux Principles
Explore the foundational principles of Redux to manage application state in Angular. Learn how to create a single store, dispatch actions to update state, and use reducers to apply changes. This lesson provides hands-on exercises to build a store, define actions, and implement reducers following Redux's unidirectional data flow.
The three principles of Redux
Redux is based on the following three principles:
-
A Redux app should have a single source of truth called the store.
-
The store is read-only and is mutated solely by dispatching actions.
-
Changes to the store are made using pure functions called reducers.
Let’s discuss each principle in detail.
The first principle
In Redux, we keep our application’s state in a single JavaScript object called the store. The components/views of our applications subscribe to the store for required data.
Exercise: Create a store
Let’s create our first store from scratch:
-
Declare a variable named
storeand initialize it with an empty object ...