I am fairly new in react native( "react-native": "0.65.1"). When I tried to use TextInput component I get ["No Command found with name "focus"][1]. I did not understood the problem. Here my code:
const [text, setText] = useState('');
<TextInput
style={{height: 40}}
placeholder="Enter name"
onChangeText={text => setText(text)}
defaultValue={text}
/>
Can anybody help me for understanding the problem? Thank you! [1]: https://i.stack.imgur.com/FLdxK.png
Accessing the native element in react native works differently.
React.ref that will hold the native element functions.So to access the focus function of a textinput element you would do something like this
//code before your return your jsx
const textInputRef = useRef({});
...
//your other variables and stuff
...
return (
....
<TextInput
style={{height: 40}}
placeholder="Enter name"
onChangeText={text => setText(text)}
defaultValue={text}
ref={textInputRef}
/>
)
You may save yourself some debugging time if you verify that the focus function exists on your ref
// one liner
textInputRef.current.focus.?()
//verbose
if(textInputRef.current.focus)
textInputRef.current.focus