react-native-actions-sheet: Usage example for Typescript - getting an error

Hello,

I posted this issue on SO regarding the usage with Typescript. Can you please assist?

https://stackoverflow.com/questions/68757797/typescript-createref-for-actionsheet-react-native

export default function MyFunc(){
   const actionSheetRef = createRef<ActionSheet>()
   useEffect(() => {
        actionSheetRef.current?.setModalVisible(props.open)
   }, [props.open])
   return (
        <>
            <ActionSheet
                ref={actionSheetRef}
                onClose={props.onClose}
            >
            // more code here  ....
        <>)
}

I also added a tag for your project so others can find it easier.

Thanks for the great library!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@johnbonds

const actionSheetRef = React.useRef<ActionSheet>(null)

should work.

Fixed in v0.5.3. Use ActionSheetRefObject type.

const actionSheetRef = createRef<ActionSheet>() <ActionSheet ref={actionSheetRef} … />

The above works for me with v0.54.

Thanks.

Use as it is used in the example. Don’t use createRef in functional components. Use useRef<ActionSheet>().