catamphetamine / react-phone-number-input

React component for international phone number input
http://catamphetamine.gitlab.io/react-phone-number-input/
MIT License
915 stars 193 forks source link

Metadata marked as required but gets undefined #426

Closed kirkegaard closed 11 months ago

kirkegaard commented 11 months ago

When using import PhoneInputWithCountry from "react-phone-number-input/react-hook-form"; im getting a warning:

Screenshot 2023-08-07 at 14 24 29
$ yarn why react-hook-form
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "react-hook-form"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-hook-form@7.45.4"
info Has been hoisted to "react-hook-form"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "1.91MB"
info Disk size with unique dependencies: "1.91MB"
info Disk size with transitive dependencies: "1.91MB"
info Number of shared dependencies: 0
✨  Done in 0.17s.

$ yarn why react-phone-number-input
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "react-phone-number-input"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-phone-number-input@3.3.1"
info Has been hoisted to "react-phone-number-input"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "9.73MB"
info Disk size with unique dependencies: "43.2MB"
info Disk size with transitive dependencies: "43.32MB"
info Number of shared dependencies: 9
✨  Done in 0.35s.

$ yarn why libphonenumber-js
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "libphonenumber-js"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "libphonenumber-js@1.10.39"
info Reasons this module exists
   - "react-phone-number-input" depends on it
   - Hoisted from "react-phone-number-input#libphonenumber-js"
info Disk size without dependencies: "9.84MB"
info Disk size with unique dependencies: "9.84MB"
info Disk size with transitive dependencies: "9.84MB"
info Number of shared dependencies: 0
✨  Done in 0.18s.
kirkegaard commented 11 months ago

https://codesandbox.io/p/sandbox/jolly-shape-9np7rm

Prooksius commented 11 months ago

The same problem. Temporarily fixed this by importing metadata and explicitly assigning it to PhoneInput.

import metadata from 'libphonenumber-js/min/metadata'
...
<PhoneInputWithCountry
    international
    metadata={metadata}
Haraldson commented 11 months ago

Experiencing the same as well.

catamphetamine commented 11 months ago

Turns out that the previous refactoring that removed .defaultProps has left .isRequired on those props and those .isRequired statements should've been removed too.

Published react-phone-number-input@3.3.2.