Помогите переписать с if на switch
dispatch(action) {
if (action.type === "ADD-POST") {
let newPost = {
id: 5,
message: this._state.profilePage.newPostText,
likeCount: 0,
};
this._state.profilePage.postData.push(newPost);
this._rerenderEntireTree(this._state);
} else if (action.type === "UPDATE-NEW-POST-TEXT") {
this._state.profilePage.newPostText = action.newText;
this._rerenderEntireTree(this._state);
} else if (action.type === "REMOVE-POST") {
let newPost = {
id: 5,
message: this._state.profilePage.newPostText,
likeCount: 0,
};
this._state.profilePage.postData.pop(newPost);
this._rerenderEntireTree(this._state);
}
},
Источник: Stack Overflow на русском