鍍金池/ 問答/HTML/ react-redux this.props為 undefind

react-redux this.props為 undefind

修改state時,this.props為 undefind
clipboard.png

clipboard.png
不知道是什么原因

回答
編輯回答
祈歡

從你發(fā)的代碼中看不出問題來。

2017年4月12日 16:26
編輯回答
熟稔

看看你的根配置文件和mapstatetoprops

2017年8月21日 00:36
編輯回答
葬愛

問題出在第一幅圖的 17 行:

return Object.assign(state.todos, pp)

根據你的代碼,我想你想要的應該是這樣:

return Object.assign(state, {todos: pp})

請查閱 Object.assign 的文檔再熟悉下它的用法。

并且,按照 Redux 的不可變原則,建議你改成這樣:

return Object.assign({}, state, {todos: pp})
// 或者
return {...state, todos: pp}

希望對你有幫助。

2017年3月16日 05:56