File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2-
2+ import { useDispatch } from 'react-redux' ;
3+ import { Types } from '../../store/reducer/example-reducer' ;
34// import { Container } from './styles';
45
56export default function ItemList ( { item } ) {
7+
8+ const dispatch = useDispatch ( ) ;
9+
10+ function remove ( ) {
11+ let id = item . id
12+ dispatch ( { type : Types . REMOVE , id } )
13+ }
14+
615 return (
716 < span >
817 { item . text } - { item . createAt }
18+ < button type = "button" onClick = { remove } > DELETE</ button >
919 </ span >
1020 ) ;
1121}
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ import { createActions, createReducer } from 'reduxsauce';
55 * Ex.: Type.ADD e add = { type: Type.ADD, params }
66 */
77export const { Types, Creators } = createActions ( {
8- add : [ "note" ]
8+ add : [ "note" ] ,
9+ remove : [ "id" ]
910} )
1011
1112const INITIAL_STATE = {
@@ -16,6 +17,10 @@ const add = (state = INITIAL_STATE, action) => {
1617 return { ...state , data : [ ...state . data , action . note ] }
1718}
1819
20+ const remove = ( state = INITIAL_STATE , action ) => {
21+ return { ...state , data : state . data . filter ( note => note . id !== action . id ) }
22+ }
23+
1924/**
2025 * Criando os reducers
2126 * Ex.: [Types.ADD]: add == switch actions.type
@@ -27,4 +32,5 @@ const add = (state = INITIAL_STATE, action) => {
2732
2833export default createReducer ( INITIAL_STATE , {
2934 [ Types . ADD ] : add ,
35+ [ Types . REMOVE ] : remove
3036} )
You can’t perform that action at this time.
0 commit comments