Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

TypeError: a is undefined #404

Open
GusMartins499 opened this issue May 23, 2021 · 0 comments
Open

TypeError: a is undefined #404

GusMartins499 opened this issue May 23, 2021 · 0 comments

Comments

@GusMartins499
Copy link

GusMartins499 commented May 23, 2021

Hi devs, somebody can help-me ?

This is my code, and, i have an error (screenshot), but i don't understand why this is happening

This is my input component

import React, { InputHTMLAttributes, useEffect, useRef } from 'react';
import { useField } from '@unform/core';

const Input: React.FC<InputProps> = ({ name, icon: Icon, ...rest }) => {
  const inputRef = useRef<HTMLInputElement>(null);
  const {
    fieldName, defaultValue, error, registerField,
  } = useField(name);

  useEffect(() => {
    registerField({
      name: fieldName,
      ref: inputRef.current,
      path: 'value',
    });
  }, [fieldName, registerField]);

  return (
    <div className="input-container">
      {Icon && <Icon size={20} color="#fff" />}
      <input
        defaultValue={defaultValue}
        ref={inputRef}
        {...rest}
      />
    </div>
  );
};

export default Input;

This is my form in SignUp page

import { Form } from '@unform/web';
import { FormHandles } from '@unform/core';
const formRef = useRef<FormHandles>(null);

<Form  ref={formRef} onSubmit={handleSubmit}>
            <Input name="name" icon={FiUser} placeholder="Nome" type="text" />
            <Input name="email" icon={FiMail} placeholder="E-mail" type="email" />
            <Input name="password" icon={FiLock} placeholder="Senha" type="password" />
            <Button type="submit">Cadastrar</Button>
</Form>

This is the error

image

Package.json

    "@unform/core": "2.1.5",
    "@unform/web": "2.1.5",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "typescript": "^4.1.2",

How i resolve this error ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant