내 감속기가 Redux 상태 트리를 업데이트하지 않고 해결책을 찾지 못해서 도움을 얻을 수 있기를 바랍니다. 이건 내 코드입니다 : 응용 프로그램Redux 상태가 업데이트되지 않습니다.
class App extends Component {
componentWillMount() {
this.props.fetchFirebaseData('gallery')
}
function mapStateToProps(state) {
console.log('state',state.firebaseReducer)
return {
galleryItems: state.firebaseReducer
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(firebaseActions, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(App)
감속기
import Immutable from 'seamless-immutable'
import { loadFirebaseData } from '../actions/firebaseActions'
const FETCH_FIREBASE_DATA = 'FETCH_FIREBASE_DATA'
const initialState = Immutable({})
export default function firebaseReducer(state = initialState, action) {
switch (action.type) {
case FETCH_FIREBASE_DATA:
return state
.set('firebaseData', fetchData(action))
}
return state
}
function fetchData(action) {
return {
firebaseData: action.firebaseData
}
}
그리고 감속기의 실행을 로그 아웃하는 경우 :
import Immutable from 'seamless-immutable'
import { loadFirebaseData } from '../actions/firebaseActions'
const FETCH_FIREBASE_DATA = 'FETCH_FIREBASE_DATA'
const initialState = Immutable({})
export default function firebaseReducer(state = initialState, action) {
console.log(1)
switch (action.type) {
case FETCH_FIREBASE_DATA:
console.log(2)
return state
.set('firebaseData', fetchData(action))
}
console.log(3)
console.log('state', state)
return state
}
function fetchData(action) {
return {
firebaseData: action.firebaseData
}
}
콘솔 쇼 :
1
3
state: Object {__immutable_invariants_hold: true}
1
3
Object {__immutable_invariants_hold: true}
Object {__immutable_invariants_hold: true}
1
2
따라서 마지막 단계에서 상태가 업데이트되지 않습니다. 왜 그런 생각을 했니? 감사합니다.