Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.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 使用formik时在标签中显示活动状态_Javascript_Reactjs_Formik - Fatal编程技术网

Javascript 使用formik时在标签中显示活动状态

Javascript 使用formik时在标签中显示活动状态,javascript,reactjs,formik,Javascript,Reactjs,Formik,我一直在使用表单的redux表单,但我想切换到formik,但我找不到显示我的输入字段是否处于活动状态的方法。就像我以前使用的redux表单 {label && ( <Label isActive={meta !== undefined && meta.active} css={labelCss}> {label} </Label> )} {label&&( {label} )} 但是,如何在formik中做到这一点

我一直在使用表单的
redux表单
,但我想切换到
formik
,但我找不到显示我的输入字段是否处于活动状态的方法。就像我以前使用的
redux表单

{label && (
   <Label isActive={meta !== undefined && meta.active} css={labelCss}>
    {label}
   </Label>
)}
{label&&(
{label}
)}
但是,如何在formik中做到这一点呢

这是我的密码

const TextField = ({ label, type, ...props }) => {
  const [field, meta] = useField(props);
  const errorText = meta.error && meta.touched ? meta.error : "";
  console.log('meta', meta)
  return (
    <>
      <InputGroup>
        {label && <Label>{label}</Label>}
        <Input type={type} {...field} {...props} />
      </InputGroup>
    </>
  );
};
consttextfield=({label,type,…props})=>{
const[field,meta]=useField(props);
常量errorText=meta.error&&meta.toucted?meta.error:;
console.log('meta',meta)
返回(
{label&&{label}
);
};

我在formik中没有看到任何活动道具

您可以使用输入字段支持的
onFocus
prop

const [active, setActive] = useState(false)

<Input
  onBlur={() => setActive(false)}
  onFocus={() => setActive(true)}

  {...otherProps}

/>

const[active,setActive]=useState(false)
setActive(假)}
onFocus={()=>setActive(true)}
{…其他道具}
/>

它不支持formik。您需要在TextField状态中处理活动状态。只需使用
handleFocus
handleBlur
功能即可更新激活状态。