-
Notifications
You must be signed in to change notification settings - Fork 345
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
When do you support hooks? #112
Comments
useRef sir |
@huuthinh245 please explain how can we use useRef? |
@MahmudHasanMenon import ActionSheet from 'react-native-actionsheet'
const Demo = (props) => {
const refActionSheet = useRef(null);
showActionSheet = () => {
if (refActionSheet.current) {
refActionSheet.current.show();
}
}
return (
<View>
<Text onPress={this.showActionSheet}>Open ActionSheet</Text>
<ActionSheet
ref={refActionSheet}
title={'Which one do you like ?'}
options={['Apple', 'Banana', 'cancel']}
cancelButtonIndex={2}
destructiveButtonIndex={1}
onPress={(index) => { /* do something */ }}
/>
</View>
)
} |
you save my day @allanmaral |
Thanks to you @allanmaral !! |
the |
Thank you @allanmaral <3 |
Property 'show' does not exist on type 'never'.ts(2339)
|
I am getting error const refActionSheet = useRef(null); in code(undefined is not a function) by @allanmaral
|
@badalWiser you are invoking the The updated sample code using TypeScript for future reference. Remember to install import { Text, View } from 'react-native';
import { useRef } from 'react';
import ActionSheet from 'react-native-actionsheet'
const Demo: React.FC = (props) => {
const refActionSheet = useRef<ActionSheet>(null);
const showActionSheet = () => {
if (refActionSheet.current) {
refActionSheet.current.show();
}
}
return (
<View>
<Text onPress={showActionSheet}>Open ActionSheet</Text>
<ActionSheet
ref={refActionSheet}
title={'Which one do you like ?'}
options={['Apple', 'Banana', 'cancel']}
cancelButtonIndex={2}
destructiveButtonIndex={1}
onPress={(index) => { /* do something */ }}
/>
</View>
)
} |
I am using a functional component, not a class component.
How should I give ref to ?
ref = {ref => this.ActionSheet = ref} ??
This method cannot be used in hooks
The text was updated successfully, but these errors were encountered: