Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React-Formik:如何使用自定义onChange和onBlur_Javascript_Forms_Reactjs - Fatal编程技术网

Javascript React-Formik:如何使用自定义onChange和onBlur

Javascript React-Formik:如何使用自定义onChange和onBlur,javascript,forms,reactjs,Javascript,Forms,Reactjs,我从react的库开始,但我不知道如何使用道具handleChange和handleBlur 根据,把手可以设置为上的支柱,然后必须手动传递到 我试过了,但没有成功: (为了更清晰,我保留了关于把手的代码) 从“React”导入React; 从“Formik”导入{Formik,Field,Form}; 从“ramda”导入{indexBy,map,compose}; 从“重新组合”导入{withReducer}; 常量MyInput=({字段、窗体、把手栏,…rest})=> {form.er

我从react的库开始,但我不知道如何使用道具handleChange和handleBlur

根据,把手可以设置为
上的支柱,然后必须手动传递到

我试过了,但没有成功: (为了更清晰,我保留了关于把手的代码)

从“React”导入React;
从“Formik”导入{Formik,Field,Form};
从“ramda”导入{indexBy,map,compose};
从“重新组合”导入{withReducer};
常量MyInput=({字段、窗体、把手栏,…rest})=>
{form.errors[field.name]&&
form.toucted[字段.名称]&&
{form.errors[field.name]}
}
;
常数indexbyd=indexBy(o=>o.id);
常量mapToEmpty=map(()=>“”);
const EmailsForm=({fieldsList})=>
{
//log(“验证”{values});
常量错误={values};
返回错误;
}}
onSubmit={values=>{
log(“onSubmit”,{values});
}}
handleBlur={e=>console.log(“bluuuurr”,{e})}
渲染={({isSubmitting,handleBlur})=>
提交
}
/>;
这种方法有什么问题?
handleBlur和handleChange实际应该如何使用?

您需要从
Formik
中删除第一个
handleBlur
,因为模糊事件仅在字段级别有效,并在字段元素中执行以下操作:

<Field
    component={MyInput}
    name="email"
    type="email"
    onBlur={e => {
        // call the built-in handleBur
        handleBlur(e)
        // and do something about e
        let someValue = e.currentTarget.value
        ...
    }}
/>
{
//调用内置把手
车把(e)
//对e做点什么
让someValue=e.currentTarget.value
...
}}
/>

请参见

只要不需要操纵该值,这就可以了。在我的例子中,我想在自定义模糊处理程序中重新格式化字段的值,因为
setFieldValue()
不是异步的,这会触发验证问题。请看,我认为这是一个单独的Formik问题,在同一个字段上执行
setFieldValue()
后,如果没有一些解决方法,就无法立即获得更新的字段值。我是那次讨论的参与者之一。
<Field
    component={MyInput}
    name="email"
    type="email"
    onBlur={e => {
        // call the built-in handleBur
        handleBlur(e)
        // and do something about e
        let someValue = e.currentTarget.value
        ...
    }}
/>