我有这个 reducer 函数,我在里面将 voteScore 的值增加了 1。这是在不打破 reducer 函数应该是纯函数的约束的情况下正确的方法吗?
function comment (state = {}, action) {
...
switch(action.type) {
...
case UP_VOTE_COMMENT:
const upVoteScore = parseInt(state[id]['voteScore'], 10) + 1
return {
...state,
[id]: {
...state[id],
voteScore: upVoteScore
}
}
}
}