Redux Toolkit
Last updated
Last updated
includes the Redux core, as well as other key packages like(Redux Thunk and Reselect, immer) and helper functions
A with simplified configuration options. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includes redux-thunk
by default, and enables use of the Redux DevTools Extension.
A 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
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"
A that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses the to let you write simpler immutable updates with normal mutative code, like state.todos[3].completed = true
.
A that returns an action creator function for the given action type string. The function itself has toString()
defined, so that it can be used in place of the type constant.