Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textinputref.isfocused is not a function #51

Open
mulayam1005 opened this issue Sep 3, 2020 · 3 comments
Open

textinputref.isfocused is not a function #51

mulayam1005 opened this issue Sep 3, 2020 · 3 comments

Comments

@mulayam1005
Copy link

Simulator Screen Shot - iPhone X - 2020-09-03 at 15 22 31

I have encountered this error while usign useRef hook

can you please give an example how to use this with useRef hook or functional component.

Here is my code:

const [household, setHousehold] = useState('')
const householdRef = useRef(null)

return(
 <KeyboardAwareScrollView getTextInputRefs={() => { return [householdRef] }} style={styles.container}>
    <TextInput multiline={true} placeholderTextColor={inputPlaceholderTextColor} placeholder='write your answer here..' style={styles.input} />
    <TextInput multiline={true} placeholderTextColor={inputPlaceholderTextColor} placeholder='write your answer here..' style={styles.input} />
    <TextInput multiline={true} placeholderTextColor={inputPlaceholderTextColor} placeholder='write your answer here..' style={styles.input} />
    <TextInput multiline={true} placeholderTextColor={inputPlaceholderTextColor} placeholder='write your answer here..' style={styles.input} />
    <TextInput {...props} ref={householdRef} multiline={true} placeholderTextColor={inputPlaceholderTextColor} placeholder='write your answer here..' style={styles.input} />
 </KeyboardAwareScrollView>
)

This is just a test so i have set only one ref.

{
 "versions": {
           "react": "16.13.1",
           "react-native": "0.63.2",
           "react-native-keyboard-aware-scrollview": "^2.1.0",
 },
"device": "iPhoneX"
}
@leiwan5
Copy link

leiwan5 commented Oct 2, 2020

Try householdRef.current ?

@sufyansalim
Copy link

Try householdRef.current ?

hi could you explain how to add this in the above code?

@leiwan5
Copy link

leiwan5 commented Jun 7, 2023

It depends on how you get the reference. If you set a function to the prop ref, you would get a instance and you would be able to use ref.isFocused(). But is a deprecated way, instead using a Ref object created with useRef is recommanded. Here is some sample code. You can check out the documentation of useRef.

const ref = useRef(null);
<TextInput ref={ref} ... />
ref.current?.isFocused()

Try householdRef.current ?

hi could you explain how to add this in the above code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants