这是我正在做的-
当前,我在reducer的authProcessCurrentData中有一个空数组。 最初,我在其中设置数组,就像..
[{label:'sign in', id:uuid, type:button}...] //buttonArray
[{label:'Pleae login in', id:uuid, type:text}...] //buttonArray
这是我在超时时插入的内容(一个接一个)。一旦我拥有了完整的格式化数组,我就会以化简器类型AUTH_SCREEN_CURRENT_DATA进行分派。
这工作正常,但在下一个事件中,将插入具有不同标签的相同数组(最初是文本数据,然后是上一个按钮)。我正在从存储中获取新数据,但有警告A state mutation was detected between dispatches
。我尝试了不同的化简键使用不同的数组插入方法,但是没有运气。有帮助吗?
export const injectProps = index =>{
const { dispatch, getState } = storeObj.store;
let currentBotData = getState().onBoarding.authProcessData;
let {textData, identifier} = currentBotData[index];
let buttons = currentBotData[index].buttonsData
let i = 0;
dispatch({ type: "AUTH_SCREEN_RESPONSE_REQUEST" });
let array = [];
Array.prototype.insert = function(ind, item) {
this.splice(ind, 0, item);
};
let interval = setInterval(async() => {
let currentDataObjs = getState().onBoarding.authProcessCurrentData?getState().onBoarding.authProcessCurrentData:[];
let newTextArray = [...currentDataObjs]
newTextArray.insert(0,textData[i]);
if (i <= textData.length-1) {
dispatch({ type: "AUTH_SCREEN_CURRENT_DATA", currentData: newTextArray, currentScreen:index});
i += 1;
}
if (i === textData.length){
clearInterval(interval);
setTimeout(() => {
dispatch({ type: "ONBOARDING_LOADER_STOP" });
}, 1000);
let nextArray = [...buttons,...newTextArray];
console.log("nextArray nextArray ",nextArray)
return new Promise(_=>_(dispatch({
type: "AUTH_SCREEN_CURRENT_DATA",
currentData: nextArray,
currentScreen:index
})
));
}
if (i > textData.length){
clearInterval(interval);
return setTimeout(() => {
return new Promise(_=>_( dispatch({
type: "ONBOARDING_LOADER_STOP"
})))
}, 1000);
}
}, 1000);}