Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 304
Dimitri Kopriwa Avatar asked Apr 13 '20 16:04

Dimitri Kopriwa


People also ask

What is an invalid prop type error in textinput?

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.

Is there an invalid prop in React Native textinput?

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`.

How to pass values from state/variable to prop in textinput?

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.

Is prop value a string or a string?

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.


1 Answers

Just convert your number to a string

<TextInput value={postalCode.toString()} ...
like image 128
HermitCrab Avatar answered Sep 28 '22 13:09

HermitCrab