0
在我的反應/ Redux的應用有下列行爲接收狀態突變錯誤
export function getSeatingChartConfiguration(team) {
return function(dispatch) {
ref.child(team.key).once('value').then(function(snapshot) {
dispatch(loadSeatingChart(snapshot.val()));
});
};
}
export function saveSeatingChartSection(key, sectionData){
return function(dispatch) {
ref.child(key).once('value').then(function(snapshot) {
let data = snapshot.val();
let sections = data.sections;
let index = snapshot.val().sections.map((el) => el.name).indexOf(sectionData.name);
if(index !== -1) {
sections[index] = sectionData;
} else {
sections.push(sectionData);
}
data.sections = sections;
ref.child(key).update(data, function(error) {
dispatch(loadSeatingChart(data));
});
});
};
}
這裏是減速
export default function seatingChart(state = {}, action) {
switch(action.type) {
case actionTypes.LOAD_SEATING_CHART_CONFIGURATION:
return action.seatingChartConfiguration;
default:
return state;
}
}
我沒有得到任何錯誤,當getSeatingChartConfiguration()
的調用,但我已經收到Error: A state mutation was detected between dispatches, in the path
seatingChart.sections.2.points .
我需要在我的動作或減速器中更改以不改變狀態。
如果snapshot.val的結果是相同的對象,而不是一個新的,你是變異的,如果複製會發生什麼部分? – Axnyff
我試圖將'data'定義更改爲'let data = JSON.parse(JSON.stringify(snapshot.val()));'並且收到相同的錯誤。 –