我想访问props.group
组件中的ViewGroup
,但我的道具返回undefined
我尝试使用构造函数,但它生成相同的undefined
。
ViewGroup.js
class ViewGroup extends React.Component{
render() {
console.log(this.props.group, ' CONSOLE LOG PROPS GROUP')
return(
<div style={styles.base}>
</div>
)
}
}
DataGroup Component
import ViewGroup from './ViewGroup'
class DataGroup extends React.Component{
render(){
const { dataGroups } = this.props
return(
<div>
<ViewGroup
group={dataGroups}
/>
</div>
)
}
}
const mapStateToProps = state => {
const dataGroups = state.groupReducer.group ? state.groupReducer.group :[]
return {
dataGroups
}
};
export default connect(mapStateToProps)(DataGroup)
Actions.js
export function loadGroup(data){ return { type: LOAD_GROUP, data }};
export default function groupReducer( state= {}, action = {}){
switch (action.type){
case LOAD_GROUP:
return {
...state,
group: action.data
}
default:
return state
}
}
减速
const reducer = combineReducers({
Auth,
groupReducer,
persistStore,
form: formReducer
});
答案 0 :(得分:0)
我认为:const dataGroups = state.groupReducer.group ? state.groupReducer.group :[]
实际应该是:const dataGroups = state.group ? state.group :[]
。