Open reboottime opened 1 year ago
createSlice
Before the advent of the redux toolkit, managing action types and breaking down a large global state into manageable, cohesive modules was a common challenge faced by many.
The introduction of the Redux Toolkit has proposed a standardized way for modularizing and generating Redux components, exemplified in this Gist. Here are a few key benefits of using the toolkit:
counterSlices.actions
object provides access to all action creators, with action types generated by these creators having a counter prefix. This enhances both the ease of accessing action creators and understanding action types, as shown in the code example below:
export const { increment, decrement, incrementByAmount } = counterSlice.actions;
configureStore
accepts a reducer
to combine the module's initial state value and reducers logics.export const store = configureStore({
reducer: counterSlice.reducer,
})
Redux-related files are organized under the redux
folder and named after the respective features they represent.
For a suggested example, please refer to this link.
Overview
In this note, I will delve into the world of redux toolset for managing global state in React applications. This article covers three parts:
Ecosystem packages
Core concepts in Redux
1. The single flow of data
Redux implements the single flow of data concept. There are three concepts
Through user interaction on the view, an action is triggered, leading to a state change that subsequently updates the user interface.
Derived concepts
2. Action creator and reducer