我組合減速器並在index.js中添加初始狀態。React-redux:爲什麼我發送一個動作狀態改變但視圖不更新?
const store = createStore(Reducers, initialState);
和mapDispatchToProps
這樣的:
const mapDispatchToProps = (dispatch, ownProps)=>({
getAboutMeData:()=> dispatch(getAboutMeData())
});
,我的行爲是這樣的:
export const getAboutMeData =() => ({
type: GET_ABOUTME_DATA,
payload:{
basicInfo: {
name: "change data",
job: "change data",
hometown: "change data",
birthday: "change data",
degree: "change data",
livein: "change data",
avater: "change data",
school: "change data",
majorIn: "change data"
}
}
})
更新我的組件時,使用componentDidMount
由:
componentDidMount(){
const {getAboutMeData} =this.props;
getAboutMeData();
}
和我紅眼ERS是這樣的:
export default function aboutMe(state= {}, action) {
switch(action.type) {
case GET_ABOUTME_DATA:
return action.payload
default:
return state
}
}
但我的組件沒有更新狀態,我不知道爲什麼。
你已經mapStateToProps配置 –
是的,我做到了,常量mapStateToProps =(州,ownProps)=>( { aboutMe:state.aboutMe }) 出口默認連接( mapStateToProps, mapDispatchToProps )(AboutMe) – huxinmin
可以告訴你你的組件 –