Redux Toolkit
includes the Redux core, as well as other key packages like(Redux Thunk and Reselect, immer) and helper functions
Configure Store
A
configureStore()
function with simplified configuration options. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includesredux-thunk
by default, and enables use of the Redux DevTools Extension.
Create Slice
A
createSlice()
function that accepts a set of reducer functions, a slice name, and an initial state value, and automatically generates a slice reducer with corresponding action creators and action types. Default(unknown action type) returns current.Mutations of state will auto create a new object on change as needed
Old Helpers but unneeded b/c create Slice
A
createReducer()
utility that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses theimmer
library to let you write simpler immutable updates with normal mutative code, likestate.todos[3].completed = true
.
A
createAction()
utility that returns an action creator function for the given action type string. The function itself hastoString()
defined, so that it can be used in place of the type constant.
However, we can take advantage of
createAsyncThunk
to clean up the above code, and to create those three actions automatically:What
createAsyncThunk
does here, is to automatically create an action creator for each Promise state. For example if we name our async thunk "users/getUsers", it generates:pending: "users/getUsers/pending"
rejected: "users/getUsers/rejected"
fulfilled: "users/getUsers/fulfilled"
Last updated