<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
Uncaught TypeError: _this.props.onSubmit is not a function
当我尝试console.log(this.form)有submitForm功能。
console.log(this.form)
submitForm
有解决方案的人吗?
-Formik版本:最新-React版本:v16-操作系统:Mac OS
找到了罪魁祸首。
onSubmitCallbackFormik道具不再有。应该将其更改为onSubmit
onSubmitCallback
onSubmit