Skip to content

Commit

Permalink
uso e tipagem de seletores
Browse files Browse the repository at this point in the history
  • Loading branch information
DenyCodes committed Jan 10, 2024
1 parent ea12ce7 commit 5447c0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useSelector } from 'react-redux'
import * as S from './styles'

import cesta from '../../assets/cesta.png'
import { paraReal } from '../Produto'
import { useSelector } from 'react-redux'

import { RootReducer } from '../../store'

const Header = () => {
const itens = useSelector((state: RootReducer) => state.carrinho.itens)

const valorTotal = itens.reduce((acc, item) => {
acc += item.preco
return acc
Expand Down
6 changes: 3 additions & 3 deletions src/store/reducers/carrinho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const carrinhoSlice = createSlice({
initialState,
reducers: {
adicionar: (state, action: PayloadAction<Produto>) => {
const produtos = action.payload
const novoProduto = action.payload

if (state.itens.find((produtos) => produtos.id === produtos.id)) {
if (state.itens.find((produtos) => produtos.id === novoProduto.id)) {
alert('item já adicionado')
} else {
state.itens.push(produtos)
state.itens.push(novoProduto)
}
}
}
Expand Down

0 comments on commit 5447c0b

Please sign in to comment.