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

How to 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={refsFocus}                /></View><TouchableOpacity                onPress={()=> { refsFocus.current.focus();} }><Text>Edit text input</Text></TouchableOpacity></>    );};

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

Error Message:

Object is possibly 'null'

const refsFocus: React.MutableRefObject<null>

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


Viewing all articles
Browse latest Browse all 6287

Trending Articles