Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Focus on TextInput on click of button in react native

$
0
0

I am trying to set focus on TextInput when I click on edit button, but I am getting error.

Below is my code:

const MyProfileScreen = (props: any) => {    const refsFocus = useRef(null);    return (<><View><TextInput                    placeholder={'editable test'}                    placeholderTextColor={'red'}                    style={{color: 'red'}}                    ref={'lastNameRef'}                /></View><TouchableOpacity                onPress={()=> { refsFocus.lastNameRef.focus();} }><Text>Edit text input</Text></TouchableOpacity></>    );};

But I am getting error on onPress={()=> { refsFocus.lastNameRef.focus();} }

Error Message:Property 'lastNameRef' does not exist on type 'MutableRefObject<null>'.

I am not able to figure out what I am doing wrong


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>