first commit
This commit is contained in:
commit
86ffedffca
24 files changed
+8576
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { data } from "../../app/data";
|
||||
import type { VolumeItem } from "../../app/data";
|
||||
|
||||
// 1. Define the State interface
|
||||
export interface State {
|
||||
books: VolumeItem[];
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
books: []
|
||||
} as any;
|
||||
|
||||
const bookSlice = createSlice({
|
||||
name: "books",
|
||||
initialState,
|
||||
reducers: {
|
||||
clearList: (state: State) => {
|
||||
state.books = [];
|
||||
},
|
||||
resetList: (state) => {
|
||||
state.books = data.items;
|
||||
},
|
||||
deleteBook: (state, action) => {
|
||||
const id = action.payload;
|
||||
state.books = state.books.filter((book: VolumeItem) => book.id !== id);
|
||||
}
|
||||
},
|
||||
extraReducers: (buider) => {}
|
||||
});
|
||||
|
||||
export const { clearList, resetList, deleteBook } = bookSlice.actions;
|
||||
|
||||
export default bookSlice.reducer;
|
||||
Reference in new issue
Block a user