concat vs扩展语法 [英] concat vs spread syntax

查看:129
本文介绍了concat vs扩展语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作的一个代码库中,由于多个不同的人在处理它,所以存在很多不一致之处.

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
   }
}

我可以代替使用concat而不使用concat吗?

Instead of doing concat can I use spread syntax instead?

return [...state, action.text]

推荐答案

spread语法和Array.prototype.concat()都不会改变状态,因此尊重redux的第二条规则

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

状态为只读

State is read-only

这篇关于concat vs扩展语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆