redux fix

main
Stepan Pilipenko 1 month ago
parent 76153eede8
commit d76e86ca32

@ -2,15 +2,19 @@ import { Container, CssBaseline, ThemeProvider } from '@mui/material'
import { Shop } from './pages/shop'
import { blue } from '@mui/material/colors'
import { theme } from './theme'
import { Provider } from 'react-redux'
import { store } from './store'
export const App = () => {
return (
<>
<CssBaseline />
<ThemeProvider theme={theme}>
<Container maxWidth="md" sx={{ bgcolor: blue }}>
<Shop />
</Container>
<Provider store={store}>
<Container maxWidth="md" sx={{ bgcolor: blue }}>
<Shop />
</Container>
</Provider>
</ThemeProvider>
</>
)

@ -21,9 +21,10 @@ export const shopSlice = createSlice({
name: 'shop',
initialState,
reducers: {
// TODO: дописать action.payload.id
addToBasket: (state, action: PayloadAction<AddBasketAction>) => {
state.products[action.payload.id].count -= action.payload.count
state.products[action.payload.id].reserved += action.payload.count
state.products[0].count -= action.payload.count
state.products[0].reserved += action.payload.count
},
},
extraReducers: builder => {

@ -1,4 +1,4 @@
import { memo, useCallback, useEffect, type JSX } from 'react'
import { memo, useCallback, useEffect } from 'react'
import styles from './shop.module.css'
import { Box, Button } from '@mui/material'
import { useAppDispatch, useAppSelector } from '../../hooks'
@ -22,7 +22,7 @@ export const Shop = memo(() => {
<Button variant="contained" onClick={handleClick}>
{'Добавить в корзину'}
</Button>
<span className={styles.shop}>{String(products)}</span>
<span className={styles.shop}>{JSON.stringify(products)}</span>
</Box>
)
})

Loading…
Cancel
Save