in react-native, I have:
Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`.
I have a postalCode
and it is numeric value.
I have set the keyboardType="numeric"
on <TextInput />
but I still have this error on ios/android/web.
How can I fix it?
Warning: Failed Prop type: Invalid prop ‘value’ of type ‘number’ supplied to ‘TextInput’, expected ‘string’ If you will see the code of the TextInput you will find we directly pass the value from the state/variable to the value prop. But the prop value requires the value to be set in the string.
React Native: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`. Fantashit February 19, 2021 4 Comments on React Native: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`.
If you will see the code of the TextInput you will find we directly pass the value from the state/variable to the value prop. But the prop value requires the value to be set in the string. Sometimes values in the state will be numeric and sometimes it will be alphanumeric.
But the prop value requires the value to be set in the string. Sometimes values in the state will be numeric and sometimes it will be alphanumeric. In this case when the value is alphanumeric then the value is treated as a string but in the case of numeric, it becomes pure numbers.
Just convert your number to a string
<TextInput value={postalCode.toString()} ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With