TypeError: a is undefined · Issue #404 · unform/unform · GitHub
Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

TypeError: a is undefined #404

Open
Open

Description

@GusMartins499

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 ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions