You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
pizza.krasnikov.pro/.history/redux/stoke/slice_20220518133432.ts

38 lines
985 B

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { fetchStoke } from './stock';
import { Stoke, StockSliceState, Status } from './types';
const initialState: StockSliceState = {
items: [],
status: Status.LOADING, // loading | success | error
};
const stokeSlice = createSlice({
name: 'stoke',
initialState,
reducers: {
setItems(state, action: PayloadAction<Stoke[]>) {
state.items = action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(fetchStoke.pending, (state, action) => {
state.status = Status.LOADING;
state.items = [];
});
builder.addCase(fetchStoke.fulfilled, (state, action) => {
state.items = action.payload;
state.status = Status.SUCCESS;
});
builder.addCase(fetchStoke.rejected, (state, action) => {
state.status = Status.ERROR;
state.items = [];
});
},
});
export const { setItems } = stokeSlice.actions;
export default stokeSlice.reducer;