I am trying to use React's
react-phone-number-input
, as follows:
{
name: 'phone',
label: 'Phone',
type: 'ui',
admin {
width: '50%',
components: {
Field: PhoneInput
}
}
}
At the top of my file I have:
import PhoneInput from 'react-phone-number-input'
import 'react-phone-number-input/styles.css'
But it gives this error in the browser console:
Warning: failed prop type: the prop 'onChange' is marked as required in 'ForwardRef', but its value is 'undefined'.
My understanding is that I need to pass in my own
onChange
handler. But I'm not sure how to do this. Shouldn't this component have its own default
onChange
handler? Am I really required to roll my own?
I was hoping this component would be more "plug and play". If this is not the case, can someone please either
provide me a working snippet of
react-phone-number-input
being used within a Payload app? Or perhaps suggest an alternative component that is simpler to plug into Payload?
@notchr @paulpopus did I see ppl working on a npm package with fields like this?
Yep! @cadebryant
https://github.com/NouanceLabs/payload-better-fields-plugin#telephone-fieldI linked the source code there too in case you just want to copy it over
Thank you so much! This is a lifesaver!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.