本文介绍了React Formik在< Formik/>之外使用SubmitForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<Formik
isInitialValid
initialValues={{ first_name: 'Test', email: '[email protected]' }}
validate={validate}
ref={node => (this.form = node)}
onSubmitCallback={this.onSubmitCallback}
render={formProps => {
const fieldProps = { formProps, margin: 'normal', fullWidth: true, };
const {values} = formProps;
return (
<Fragment>
<form noValidate>
<TextField
{...fieldProps}
required
autoFocus
value={values.first_name}
type="text"
name="first_name"
/>
<TextField
{...fieldProps}
name="last_name"
type="text"
/>
<TextField
{...fieldProps}
required
name="email"
type="email"
value={values.email}
/>
</form>
<Button onClick={this.onClick}>Login</Button>
</Fragment>
);
}}
/>
我正在尝试此解决方案 https://github.com/jaredpalmer/formik/issues/73#issuecomment-317169770 ,但它总是返回我Uncaught TypeError: _this.props.onSubmit is not a function
I'm trying this solution https://github.com/jaredpalmer/formik/issues/73#issuecomment-317169770 but it always return me Uncaught TypeError: _this.props.onSubmit is not a function
当我尝试console.log(this.form)
时,有submitForm
函数.
有解决方案的人吗?
-Formik版本:最新-React版本:v16-操作系统:Mac OS
- Formik Version: latest- React Version: v16- OS: Mac OS
推荐答案
找到了罪魁祸首.
Formik道具不再有onSubmitCallback
.应该将其更改为onSubmit
There are no longer onSubmitCallback
on Formik props. Should change it to onSubmit
这篇关于React Formik在< Formik/>之外使用SubmitForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!