В настоящее время у меня есть два редуктора, и по какой-то причине, когда я поддерживаю состояние журнала, у меня есть две копии состояния, по одной для каждого редуктора. Кроме того, нет «основного состояния» или чего-либо еще. Это не может быть прямо здесь, и я хотел бы выяснить, как это исправить.
Я пытался взять initialState
из combineReducers
и из моих редукторов. Независимо от того, что я пытаюсь, в рамках моих в настоящее время ограниченных знаний Redux я получаю два состояния.
startReducer.js
import initialState from '../initialState'
import {START} from '../constants/actionTypes'
export default function reducer(state=initialState, action){
switch (action.type){
case START:{
return {...state, started:true}
}
default:
return state
}
}
редукторы / index.js
import {combineReducers} from 'redux';
import start from './startReducer'
import move from './moveReducer'
export default combineReducers({
move: move,
start: start
})
App.js
const mapStateToProps = (state) => {
console.log("state from inside mapStateToProps: ", {...state})
return {
//I WANT to just be saying state.currentPlayer... Why two states?
currentPlayer: state.move.currentPlayer,
error: state.move.error,
gameOver: state.move.gameOver,
moves: state.move.moves,
started: state.move.started
}};
Проблема здесь в том, что когда я консоль журнала
console.log("Full State: ", store.getState())
Я понял:
>move:
currentPlayer: "white"
error: null
gameOver: false
moves: []
started: false
>start:
currentPlayer: "white"
error: null
gameOver: false
moves: []
started: false
Две копии моего состояния для каждого редуктора. Как я могу избежать этого? Что я сделал не так в своей архитектуре, которая так меня обошла?