【发布时间】:2019-04-18 09:24:00
【问题描述】:
我正在使用以下组合,并期望 a 作为道具传递。虽然它是未定义的。
请问如何解决?
import { setStatic, compose } from 'recompose'
import { connect } from 'react-redux'
export const getInitialProps = function() {
console.log(this.props.a);
}
const mapDispatchToProps = (dispatch) => ({
a: url => dispatch({type: 'a'})
})
export default compose(
connect(null, mapDispatchToProps),
setStatic('getInitialProps', getInitialProps),
)
【问题讨论】:
-
this未定义或a是? -
很好的问题。这似乎已定义。道具不是。
-
我认为你在构造函数中缺少这个绑定,或者你需要在 getintialprops 中传递这个
-
也许将 getInitialProps 更改为箭头函数并尝试。我认为您在 getInitialProps 中丢失了这个上下文,因为它是正常功能
-
箭头函数即使
this消失了
标签: reactjs redux next.js recompose