1
私はHOCを使用しているコンポーネントを持っています。 HOCはthis.contextを必要としますが、何らかの理由でthis.contextが渡されていません。私は間違って何をしていますか? TYコンテキストが私のHOCに渡されない理由
コンポーネント:
import React, { Component } from 'react';
import withTracking from './hocs/withTracking';
class NamePage extends Component {
componentDidMount() {
console.log(this.context.mixpanel) // WORKS
}
render() {
return (
...
);
}
}
NamePage.contextTypes = {
mixpanel: PropTypes.object.isRequired
};
export default withTracking('View Page: NamePage')(NamePage);
アドホック
import { lifecycle } from 'recompose';
export function withTracking(eventTitle) {
return lifecycle({
componentDidMount() {
console.log(this.context.mixpanel) // UNDEFINED - fail-y?
}
});
}
export default withTracking;
にconsole.logが正しい返しundefined
を返している場合、コンポーネントのI出力。
私は間違っていますか?おかげ