Skip to content

Commit fa28a23

Browse files
committed
Adicionando lista no local storage
1 parent bcb19fb commit fa28a23

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/store/reducer/example-reducer.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ export const { Types, Creators } = createActions({
1010
})
1111

1212
const INITIAL_STATE = {
13-
data: []
13+
data: JSON.parse(localStorage.getItem('list')) || []
1414
}
1515

1616
const 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

2023
const 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
/**

0 commit comments

Comments
 (0)