Skip to content

Instantly share code, notes, and snippets.

@mcmxc
Created January 8, 2020 12:21
Show Gist options
  • Save mcmxc/c43d9a2967e56fde5b76332fdc1fa83d to your computer and use it in GitHub Desktop.
Save mcmxc/c43d9a2967e56fde5b76332fdc1fa83d to your computer and use it in GitHub Desktop.
react-phone-number-input + ant design (antd) Input
import React, { useState, useCallback, forwardRef } from 'react';
import { Input } from 'antd';
import PhoneInput from 'react-phone-number-input/min';
import 'react-phone-number-input/style.css';
const PhoneInputComponent = forwardRef(({ onChange, ...props }, ref) => {
const handleChange = useCallback(e => onChange(e.target.value), [onChange]);
return <Input ref={ref} {...props} onChange={handleChange} />;
});
const App = () => {
const [phoneNumber, setPhoneNumber] = useState();
return (
<div className="app">
<PhoneInput
value={phoneNumber}
onChange={setPhoneNumber}
inputComponent={PhoneInputComponent}
/>
</div>
);
};
export default App;
@mcmxc
Copy link
Author

mcmxc commented May 5, 2021

just checked, this peace of code still works with v4

@ovchinnikov
Copy link

doesn't work with the latest Antd https://stackblitz.com/edit/react-dg4xxp

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