Controlled Input not working
Describe the bug
Using native-base version 3.2.2. Following the documentation of Input specifically controlled input, I have found that I could never read the value of the input. Either the documentation is incorrect or the usage doesn't work.
To Reproduce Follow the example in documentation. Check the value in onChange method.
Expected behaviour Controlled input value is not being read.
CodeSandBox/Snack link The documentation example doesn't work.
Platform
- NativeBase version - 3.2.2
- Device: iPhone 12
- OS: iOS 15
- React Native version - 0.64.3
- Expo sdk version - 43.0.2
- node >= 16
@rs6g10 Can you check this implementation and see if this solves your problem? https://snack.expo.dev/@adityaj_geekyants/example
Same issue I used onChangeText instead
@rs6g10 Can you check this implementation and see if this solves your problem? https://snack.expo.dev/@adityaj_geekyants/example
Still doesn't work. event.target.value comes undefined on both iOS and Android. Works for web though. You can try with following simple example:
import React from "react"
import { Input, Text, Center, NativeBaseProvider } from "native-base"
export const Example = () => {
const [inputText, setInputTextValue] = React.useState("")
const handleChange = (event: any) => setInputTextValue(event.target.value)
return (
<>
<Text>{inputText}</Text>
<Input
w={{
base: "75%",
md: "25%",
}}
onChange={handleChange}
placeholder="Value Controlled Input"
/>
</>
)
}
export default () => {
return (
<NativeBaseProvider>
<Center flex={1} px="3">
<Example />
</Center>
</NativeBaseProvider>
)
}
Same issue I used
onChangeTextinstead
Thanks this works but you don't get the value from event.target.value.
@rs6g10 onChangeText prop takes a callback function that receives the input's text changes so event.target.value is not applicable there and if you want to use the onChange prop you can use event.nativeEvent. https://snack.expo.dev/@cyrus2505/nativebase-starter-snack
Please update the docs then: https://docs.nativebase.io/input#controlled-input
The controlled input seems to be wrong there
Facing the same issue.
this callback directly returns value
@NilsBaumgartner1994 You can check the working example here. This will be updated in the docs soon.