Relex Redux가 포함 된 앱을 작성하고 있습니다.상태가 정의되지 않았습니다. (reactJS)
이 내 감속기입니다 :
import { INCOME_LIST } from '../actionTypes'
import Immutable from 'immutable'
const initialUserState = {
list: [{
id: 1,
label: 'List item 1'
},
{
id: 2,
label: 'List item 2'
}]
}
const listReducer = function(state = [initialUserState], action) {
switch(action.type) {
case 'INCOME_LIST':
return Object.assign({}, state, { list: action.data });
default: return state;
}
}
export default listReducer
이 내 구성 요소입니다 왜을 console.log (this.props.items가) undifined 가져 오기 '정의되지 않은'
import React, { Component, PropTypes } from 'react'
import { Link, browserHistory } from 'react-router'
import { connect } from 'react-redux'
import axios from 'axios'
class Income extends Component {
constructor(props) {
super(props)
}
}
render() {
console.log(this.props.items)
return (
<div>
test
</div>
)
}
}
const mapStateToProps = function(store) {
return {
items: state.list
};
}
export default connect(mapStateToProps)(Income);
콘솔이 있다고? 감속기에서 상태를 얻는 올바른 방법은 무엇입니까? 거기에 실수가있을 수 있습니까?
이 작업을 수행하지만 콘솔에서 정의되지 않은 상태가 발생합니다 ... 왜 내 상태 감속기를 가져올 수 없습니까? –
내부에서 console.log (state.list)를 시도해보십시오. 그것은 아무것도 –
에 화면 https://i.imgsafe.org/4e36750cf3.png –