在我的反應應用程序中,我預先加載了名爲activeWord
的reducer。未捕獲TypeError:無法在數字'0'上創建屬性'activeWord'
activeWord: 0
然後我已經在根減速器加入activeWord
import {combineReducers} from 'redux';
import activeWord from './ActiveWordReducer';
const root_reducer=combineReducers({
activeWord:activeWord
});
export default root_reducer;
然後在ActiveWordReducer
文件:
export default function WordReducer(state=null,action){
switch(action.type){
case "Active_Word":
return state.activeWord++;
}
return 0;
}
問題是,在線路state.activeWord++
,它產生一個錯誤:
Uncaught TypeError: Cannot create property 'activeWord' on number '0'
那麼我該如何解決這個問題?
更新:
在減速我也試圖返回狀態,但我仍然得到了同樣的錯誤:
export default function WordReducer(state=null,action){
switch(action.type){
case "Active_Word":
return state.activeWord++;
}
return state;
}
我相信你'state'已經'activeWord'本身,所以你只需要因爲減速器獲得切片的國家也這樣做'狀態++' – yuyokk
,不整個一個 – yuyokk