Redux
[Redux] Redux이용한 CRUD구현(Delete)
류정식
2021. 2. 9. 17:50
0. 배경
![]() |
![]() |
위의 사진처럼 각각의 성분을 읽고, 만들고, 지울 수 있는 기능을 Redux를 이용해서 만들 생각이다.
1.
<li><input onclick="
store.dispatch({
type:'DELETE'
});
" type="button" value="delete"></li>
delete버튼 클릭스 dispatch로 type을 변경해준다.
else if(action.type === 'DELETE'){
var newContents = [];
var i = 0;
while(i < state.contents.length){
if(state.selcted_id !== state.contents[i].id){
newContents.push(
state.contents[i]
);
}
i = i + 1;
}
newState = Object.assign({},state, {
contents:newContents,
mode:'welcome'
})
}
reducer 함수 내의 코드이다.
newContents에 선택된 값이 아닌 콘텐츠를 넣어준 뒤
newState에 newContents를 넣은 뒤 리턴해준다.