我正在调用我的动作' GetMobileList'在页面加载。但是在执行动作之后,没有任何东西被称为mapstatestoprops或任何reducer。它们在调用动作之前被调用,并且在调用动作之后没有任何事情发生。我在页面加载时绑定了一个列表。操作完成后,我通过父组件的props渲染列表组件。
import React, { Component } from 'react';
import GetProductsList from './list'
import GetMobileList from '../actions/index'
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
class Add extends Component
{
constructor (props) {
super(props);
}
componentDidMount()
{
GetMobileList();
}
render(){
return (
<div>
<GetProductsList mobilesList={this.props.mobiles}/>
</div>
)
}
}
function mapStateToProps (state) {
return {
mobiles: state.mobiles
}
}
export default connect (mapStateToProps,{GetMobileList}) (Add)
......................................................
export default function GetMobileList()
{
var mobiles= JSON.parse(localStorage.getItem('mobiles'));
return {
type:'MOBILE_LIST',
payload : mobiles
};
}
Index.js for Reducer
import {combineReducers} from 'redux';
import MobilesList from './mobileslist';
const rootreducer = combineReducers({
mobiles:MobilesList
});
export default rootreducer;
REDUCER -
export default function (state=null,action)
{
switch(action.type)
{
case 'MOBILE_LIST':
{
return action.payload
}
}
return state;
}
&#13;
答案 0 :(得分:1)
matchDispatchToProps
中,GetMobileList
成为道具。
因此,请尝试GetMobileList()
this.props.GetMobileList()