-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6db6fe9
commit 8f467ce
Showing
7 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
let initialState: BookShelf = []; | ||
if( localStorage.getItem("bookShelf")!==null ){ | ||
initialState = JSON.parse( localStorage.getItem("bookShelf") as string ); | ||
} | ||
|
||
export const bookShelfSlice = createSlice({ | ||
name: "bookShelf", | ||
initialState: initialState, | ||
reducers: { | ||
addBook: (state, {payload}: {payload: string}) => { | ||
state.push(payload); | ||
localStorage.setItem('bookShelf', JSON.stringify(state)); | ||
} | ||
} | ||
}) | ||
|
||
export const {addBook} = bookShelfSlice.actions; | ||
export default bookShelfSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"; | ||
import { AppDispatch, RootState } from "./store"; | ||
|
||
export const useAppDispatch: () => AppDispatch = useDispatch | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
import bookShelfReducer from "./features/bookShelfSlice"; | ||
import bookReducer from "./features/bookSlice"; | ||
|
||
export default configureStore({ | ||
const store = configureStore({ | ||
reducer: { | ||
book: bookReducer | ||
book: bookReducer, | ||
bookShelf: bookShelfReducer | ||
} | ||
}); | ||
}); | ||
|
||
export default store; | ||
export type RootState = ReturnType<typeof store.getState> | ||
export type AppDispatch = typeof store.dispatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type BookShelf = string[]; |