【发布时间】:2018-09-15 21:26:02
【问题描述】:
我定义:
class Form1 extends React.Component{
....
}
然后使用 withFormic 定义 HOC:
const Form2 = withFormik({
handleSubmit(values, { resetForm, setErrors, setSubmitting }) {
...
},
....
})(Form1);
在父组件中,我指定了一个回调函数:
<Task2 callback={this.something} />
现在,我希望 handleSubmit 调用回调函数。 我会这样做
this.props.callback()
但似乎在 HOC 中没有定义 this。
问题:如何在 HOC 中访问 Form1.props?
【问题讨论】:
-
我还没有找到答案,但是有一个解决方法:github.com/jaredpalmer/formik/issues/312