问题描述
我想将其他道具传递给MyForm组件,这超出了Formik高阶组件所允许或请求的范围。
我的代码如下:
python pgm.py arg1 arg2 'commit message'
我相信,如果您正在导出组件,并且正在使用fromik的连接或重新组合(已弃用),则它应如下所示:
import React from 'react';
import { withFormik } from 'formik';
const MyForm = props => {
const {
values,touched,errors,handleChange,handleBlur,handleSubmit,} = props;
return (
<form onSubmit={handleSubmit}>
<input
type="text"
onChange={handleChange}
onBlur={handleBlur}
value={values.name}
name="name"
/>
{errors.name && touched.name && <div id="Feedback">{errors.name}</div>}
<button type="submit">Submit</button>
</form>
);
};
const MyComponent = props => {
const MyEnhancedForm = withFormik({
mapPropsTovalues: () => ({ name: '' }),// Custom sync validation
validate: values => {
const errors = {};
if (!values.name) {
errors.name = 'required';
}
return errors;
},handleSubmit: (values,{ setSubmitting }) => {
setTimeout(() => {
alert(JSON.stringify(values,null,2));
setSubmitting(false);
},1000);
},displayName: 'BasicForm',})(MyForm);
return <MyEnhancedForm/>
}
export default MyComponent;
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)