-
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
Showing
9 changed files
with
234 additions
and
78 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
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,21 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const cartItemsSlice = createSlice({ | ||
name: 'cartitems', | ||
initialState: { | ||
value: [], | ||
}, | ||
reducers: { | ||
addToCart: (state, action) => { | ||
state.value.push(action.payload); | ||
}, | ||
setCartItems: (state, action) => { | ||
state.value = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
// Action creators are generated for each case reducer function | ||
export const { addToCart, setCartItems } = cartItemsSlice.actions; | ||
|
||
export default cartItemsSlice.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,7 @@ | ||
import { useDispatch, useSelector, useStore } from 'react-redux'; | ||
import type { AppDispatch, AppStore, RootState } from './store'; | ||
|
||
// Use throughout your app instead of plain `useDispatch` and `useSelector` | ||
export const useAppDispatch = useDispatch.withTypes<AppDispatch>(); | ||
export const useAppSelector = useSelector.withTypes<RootState>(); | ||
export const useAppStore = useStore.withTypes<AppStore>(); |
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,14 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import cartItemsReducer from './cart/cartItem'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
cartitems: cartItemsReducer, | ||
}, | ||
}); | ||
|
||
// Infer the `RootState` and `AppDispatch` types from the store itself | ||
export type RootState = ReturnType<typeof store.getState>; | ||
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} | ||
export type AppDispatch = typeof store.dispatch; | ||
export type AppStore = typeof store; |
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,10 +1,14 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
import './index.css' | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App.tsx'; | ||
import './index.css'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from './app/store.ts'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
<Provider store={store}> | ||
<App /> | ||
</Provider> | ||
</React.StrictMode>, | ||
) | ||
); |
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
Oops, something went wrong.