concat vs spread syntax

流过昼夜 提交于 2019-12-12 04:15:33

问题


I'm working a codebase where it has lots of inconsistency as it has been worked on by multiple different person.

function todos(state = [], action) {
   switch (action.type) {
      case 'ADD_TODO':
      return state.concat([ action.text ])
   default:
      return state
   }
}

Instead of doing concat can I use spread syntax instead?

return [...state, action.text]


回答1:


Both, spread syntax and Array.prototype.concat() dont mutate the state, thus respecting the second rule of redux

State is read-only



来源:https://stackoverflow.com/questions/45007846/concat-vs-spread-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!