【发布时间】:2020-02-09 23:40:26
【问题描述】:
我一直在使用 React、Redux、Redux-thunk 构建应用程序。 在调用 action 时,reducer 正确接收了有效负载和类型,但它没有修改它们。
- 我的减速机:
import EditorActionTypes from './editor.types';
const INITIAL_STATE = {
editorModified: false,
tabs: [
{
name: 'main.js',
active: true
},
{
name: 'setup.js',
active: false
}
]
};
const editorReducer = ( state = INITIAL_STATE, action ) => {
switch (action.payload) {
case EditorActionTypes.SELECT_TAB:
return {
...state,
tabs: [
...state.tabs.map(
(tab, index) => index === action.payload
? tab.active = true
: tab.active = false
)
]
}
default:
return state;
}
};
export default editorReducer;
【问题讨论】: