【发布时间】:2018-03-30 03:27:53
【问题描述】:
由于 React 16.3 已经到来,我正在尝试重构我的代码以使用新的和首选的 static getDerivedStateFromProps(),但这是我目前在我的 componentWillReceiveProps 中拥有的内容
componentWillReceiveProps(nextProps) {
if (nextProps.chatId !== this.props.chatId)
this.subscribeChatMessages(nextChatId) // a redux-thunk function
}
由于静态函数不能从this调用任何东西,我该怎么办?
我可以把redux-thunk函数移到shouldComponentUpdate,但是好像没有错?
【问题讨论】:
-
你能分享
subscribeChatMessages(..)的定义吗? -
标准代码,将从后端获取一些内容并在使用 redux-thunk 异步发送数据后发送数据
标签: reactjs react-redux redux-thunk