Course Content
Introduction to Redux
Introduction to Redux
Redux Slice
A slice is a collection of reducer and action logic for a single feature of an application, often arranged in a single file. For example, all the reducer logic related to the counter is in counterSlice
.
A slice may also refer to a part of the application state for a specific feature, hence the name slice. A Redux state can be divided into multiple slices. In a chat application, the Redux Store might look like this:
Here posts
, comments
, and reactions
are separate slices of the Redux state, handled by the slice reducers postReducer
, commentsReducer
, and reactionsReducer
, respectively.
A Slice Reducer is a reducer associated with a specific slice. For example, postReducer
is called a slice reducer for postSlice
. It can also be referred to as a 'reducer' in more general terminology.
A slice in a Redux store creates a portion of a state defined by the assigned key name, which is managed by a specific reducer (slice reducer). In the previous chapter, you were given the task of creating a slice using the reducer from todosSlice
:
The overall state of this application might roughly look like this:
Since the above application has only one slice, it has only one section called todos. We can create more slices:
The state might look something like this:
Since we have not looked at what's inside the todosSlice
file, we cannot tell what data will be in there initially. In the next chapter, it will become clearer.
Thanks for your feedback!