TextInput warns that value is a number but a string is expected
Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`Short answer
The value prop of TextInput is typed as a string. If state holds a number, React Native warns that it expected a string. Keep the typed text as a string in state, show that string in value, and convert to a number only when you calculate or submit.
Fix it fast
1Find out which cause you have
Find every TextInput whose value is not a string, and see what the state behind it starts as.
grep -rn -B1 -A4 "<TextInput" src app 2>/dev/null | grep -E "value=|useState"2Match what you see, then jump to its fix
What does the error look like?
Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`
Cause 1 of 2
State is a number and is passed straight to value
1Check
The React Native docs type TextInput value as string, and it is a controlled component, so what you pass is what the native field shows.
grep -rn -E "useState\((0|[0-9.]+)\)" src app 2>/dev/null2Fix
Keep the field's text as a string in state. If the number comes from elsewhere, convert it with String() at the prop.
const [qty, setQty] = useState('1');
<TextInput value={qty} onChangeText={setQty} keyboardType="numeric" />
// number from a model object
<TextInput value={String(item.quantity)} onChangeText={...} />3Verify
Reload the app; the warning should no longer print.
npx expo start --clearConfirmed by reactnative.dev
Cause 2 of 2
onChangeText converts the text to a number before saving it
1Check
onChangeText passes the new text as one string. A number keyboard type shows digits, but the callback still gives a string, and the controlled value must be a string again on the next render.
grep -rn -E "onChangeText=.*(Number|parseInt|parseFloat)" src app 2>/dev/null2Fix
Store the raw string. Convert when you need the number. Clean the text yourself if you want to block other characters.
const [amount, setAmount] = useState('');
<TextInput
value={amount}
keyboardType="decimal-pad"
onChangeText={(t) => setAmount(t.replace(/[^0-9.]/g, ''))}
/>
const numeric = parseFloat(amount) || 0;3Verify
Type digits, then clear the field; no warning appears and the field can be empty.
npx expo start --clearConfirmed by reactnative.dev
How do I stop it coming back?
- Type the state as string in TypeScript, so a number cannot reach value.
- Parse text to numbers in one place, at submit or at calculation time.
- Use keyboardType or inputMode for the keyboard and your own code for filtering characters, since the docs do not say the keyboard blocks other input.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Expo app never leaves the splash screen
App shows the splash screen forever and no error appears
After SplashScreen.preventAutoHideAsync() the splash stays until you hide it yourself.
3 causes, each with a fixWeb apps
NativeViewGestureHandler must be used as a descendant of GestureHandlerRootView
Error: NativeViewGestureHandler must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized.
react-native-gesture-handler only recognises gestures inside GestureHandlerRootView.
3 causes, each with a fixWeb apps
React Hook "useState" cannot be called at the top level, or in a function that is not a component
The lint points at a useState line inside a helper function, an onClick handler or the top of a module
The lint rule found a hook outside a component or custom hook.
3 causes, each with a fixWeb apps
React: Maximum update depth exceeded or Too many re-renders
Maximum update depth exceeded
React stops a component that sets state again and again without end.
3 causes, each with a fixWeb apps
React Native says the application has not been registered
Application has not been registered
The native side asks JavaScript to run an app name that JavaScript never registered.
3 causes, each with a fix