'Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`
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?
Solution 1:[1]
Just convert your number to a string
<TextInput value={postalCode.toString()} ...
Solution 2:[2]
Changing keyboardType
to numeric
doesn't make your TextInput
to accept only numbers, it only changes the layout of the keyboard on your mobile device. With keyboardType=numeric
your keyboard will have only digits to make it easier for user to type numbers, it's a UX thing but it doesn't make your TextInput
of type numeric, that's why you're seeing this warning.
Solution 3:[3]
I think that the problem is in the onChange
callback.
You can call the onChangeText method like that:
onChangeText: (text) => setValue(text)
Hope it works!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | HermitCrab |
Solution 2 | rzwnahmd |
Solution 3 |