Are React and RTK Query a New Easy Way for Redux?
hackernoon.comThe standard request template looks like with manipulation of statuses and data display. It is versatile as a Swiss knife and can be completely customized. Using this template, we can perform requests of any complexity and control all the details. Let's see what our request looks like now.


First of all, let's remember what the classic request and data storage looks like with redux-saga and @reduxjs/toolkit.
// slice
// We use an enum with statuses to easily manipulate them in the future.
enum EOperationStatus {
initial = "initial",
pending = "pending",
error = "error",
success = "success",
}
const initialState: IInitialState = {
items: [],
itemsStatus: EOperationStatus.initial,
};
export const itemsSlice = createSlice({
name: "items",
initialState,
reducers: {
getItems: state => {
state.itemsStatus = EOperationStatus.pending;
},
setItems: (state, {payload}: PayloadAction) => {
state.items = payload;
},
setItemsStatus: (
state, { payload}: PayloadAction,
) => {
state.itemsStatus = payload;
},
...
// api
const getItems = async () => await HttpHandler.get("/items");
export const API = {
getItems ...
Copyright of this story solely belongs to hackernoon.com . To see the full text click HERE