Reputation: 65
const [value, setValue] = useState();
expected ';' in place of '='
I am using this npm to get Mobile Number from User with Country Code.
npm i react-phone-number-input
https://www.npmjs.com/package/react-phone-number-input/v/3.0.13
This is the example used by them.
import 'react-phone-number-input/style.css'
import PhoneInput from 'react-phone-number-input'
const [value, setValue] = useState()
return (
<PhoneInput
placeholder="Enter phone number"
value={value}
onChange={setValue}
/>
)
Please help me out. Also suggest me another possible solution to get Phone Number form User with Country Code.
Upvotes: 0
Views: 1514
Reputation: 4748
You can only use a React.js Hook
inside a functional component. So, you need to create a functional component like this:
import PhoneInput from 'react-phone-number-input';
import 'react-phone-number-input/style.css';
const MyPhoneComponent = () => {
const [value, setValue] = useState()
return (
<PhoneInput
placeholder="Enter phone number"
value={value}
onChange={setValue}
/>
)
}
export default MyPhoneComponent;
Hope this will work for you.
Upvotes: 6
Reputation: 1799
import 'react-phone-number-input/style.css'
import PhoneInput from 'react-phone-number-input'
const MyPhone = () => {
const [value, setValue] = useState();
return (
<PhoneInput
placeholder="Enter phone number"
value={value}
onChange={setValue}
/>
)
}
Upvotes: 2