I'm trying to use ant design's input component inside react-phone-number-input, as explained in this example: https://catamphetamine.gitlab.io/react-phone-number-input/ (Custom <input/>)
The main issue is that ant design's input is a CompoundedComponent and I believe it's causing some issues. Only when using ant design's input I'm getting the following error:
Unhandled Runtime Error
TypeError: element.hasAttribute is not a function
My code looks like this:
import PhoneInput from 'react-phone-number-input'
import Input from 'ant-design'
<Form.Item name="phone">
<PhoneInput inputComponent={Input} />
</Form.Item>
Is there any way I can maybe export only the Input component from the CompoundedComponent so it works with the react-phone-number-input library?
To make it workable with antd I can suggest you to make your own component inside of your react app intead of using their. Let's call this component PhoneNumberInput.tsx. You can use their functions to format and parse phone number input such as
formatPhoneNumber, parsePhoneNumber, getCountries, however take a look to the dependencies they use in their npm module. From my point of view it would be better to use directly libphonenumber-js.Then just import this component wherever you want to use it and call it:
<PhoneNumberInput/>P.S. here is a link to npm module with flags they used, however you might check their git to get only svg files and use them as images in your project
UPDATE example showed before, stores phone number as an object. To save only a string and keep it workable with antd forms you might be interested in a following example.
This component allows you to use it so simply as others antd's user inputs in Form.Item