감속기가 작동해야한다고 생각하지만 상태를 변경한다고 계속 주장합니다.돌연변이가없는 감속기의 객체 속성 업데이트
Uncaught Error: A state mutation was detected inside a dispatch, in the path:
output.outputList.0.composition
. Take a look at the reducer(s) handling the action {"type":"SET_OUTPUT_COMPOSITION",
나는 몇 시간 전에 무언가 비슷한 것을 게시했지만, 내 redux 상태가 너무 복잡하다고 생각했습니다. 이것은 내 단순화 된 버전이고 나는 아직도 돌연변이 오류를 얻고있다. 내가 뭘 잘못하고 있니? 내 redux 상태에서 수업을 사용하지 않아야합니까? 어떤 종류의 불변 라이브러리를 사용해야합니까? 도와주세요.
내 초기 돌아 오는 주
output: {
outputList: [], //composed of Output class objects
position: 0
}
출력 클래스 특성
case types.SET_OUTPUT_COMPOSITION: {
let outputListCopy = Object.assign([], [...state.outputList]);
outputListCopy[state.position].composition = action.composition;
return Object.assign({}, state, {outputList: outputListCopy});
액션
export function setOutputComposition(comp) {
return { type: types.SET_OUTPUT_COMPOSITION, composition: comp}
}
업데이트
class Output {
constructor(output) {
this.id = output.id;
this.composition = output.getComposition();
this.outputObj = output;
this.name = output.name;
this.url = output.getUrl();
}
}
export default Output;
감속기
당신의 행동을 포함 할 수 있습니까 –
@DavidBradshaw가 당신을 위해 액션을 추가했습니다 – user1189352
내가 필요한 답변을 찾았습니다 http://stackoverflow.com/questions/35362460/replace-array-item-with-another-one-without- mutating-state – user1189352