Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[UI] Ref error in PhoneIcon number input [comp-46] #405

@ecbakas

Description

@ecbakas

When I use the PhoneInput number input without any modifications and type something, it gives the following error:
app-index.tsx:25 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Way to reproduce;

  • Copy PhoneIcon number input code
  • Install package pnpm add react-phone-number-input
  • Use it somewhere and type something.

Issue may be related to the react-phone-number-input version.
"react-phone-number-input": "^3.4.12"

Issue can be solved by simply using forwardRef for PhoneInput.

const PhoneInput = React.forwardRef<
  HTMLInputElement,
  React.ComponentProps<'input'>
>(({ className, ...props }, ref) => {
  return (
    <Input
      data-slot="phone-input"
      className={cn(
        '-ms-px rounded-s-none shadow-none focus-visible:z-10',
        className
      )}
      ref={ref}
      {...props}
    />
  );
});

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