Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14445

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?

Upvotes: 19

Views: 50835

Answers (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!

Upvotes: 2

rzwnahmd
rzwnahmd

Reputation: 1082

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.

Upvotes: 6

HermitCrab
HermitCrab

Reputation: 3274

Just convert your number to a string

<TextInput value={postalCode.toString()} ...

Upvotes: 44

Related Questions