File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,21 @@ export const { Types, Creators } = createActions({
1010} )
1111
1212const INITIAL_STATE = {
13- data : [ ]
13+ data : JSON . parse ( localStorage . getItem ( 'list' ) ) || [ ]
1414}
1515
1616const add = ( state = INITIAL_STATE , action ) => {
17- return { ...state , data : [ ...state . data , action . note ] }
17+ let newData = [ ...state . data , action . note ]
18+ localStorage . clear ( )
19+ localStorage . setItem ( 'list' , JSON . stringify ( newData ) )
20+ return { ...state , data : newData }
1821}
1922
2023const remove = ( state = INITIAL_STATE , action ) => {
21- return { ...state , data : state . data . filter ( note => note . id !== action . id ) }
24+ let newData = state . data . filter ( note => note . id !== action . id )
25+ localStorage . clear ( )
26+ localStorage . setItem ( 'list' , JSON . stringify ( newData ) )
27+ return { ...state , data : newData }
2228}
2329
2430/**
You can’t perform that action at this time.
0 commit comments