catamphetamine / react-phone-number-input

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

Optional onChange() prop for PhoneInput #303

Closed RemyMachado closed 4 years ago

RemyMachado commented 4 years ago

Hello,

I'm using the prop numberInputComponent that let me use a custom input component. In fact I'm handling changes on this custom input with a third party library (Formik). Therefore, I don't need the onChange property, but only the value one.

Problem is, PhoneInput is crashing if I don't pass the onChange prop.

Possible solution: Make it optional and check if exists before calling.

Thanks in advance.

catamphetamine commented 4 years ago

Hello. This component is meant to be used with onChange — otherwise you wouldn't get the value the user has input. One could read it directly from DOMNode.value but it wouldn't be the parsed value. So onChange is required in order for this component to work.

RemyMachado commented 4 years ago

Yeah, you're right, I mixed up the purposes. Thanks for putting me back in the right track.