0

Currently trying to setup react-native-action-sheet and getting an invalid hook call

1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

I followed the example and wrapped my wrapped your top-level component with even when using hooks.

export default () => (
  <ActionSheetProvider>>
    <App />
  </<ActionSheetProvider>>
);

Wondering if it's the way I set this up:

import { Linking } from 'react-native';
import { useActionSheet } from '@expo/react-native-action-sheet';

export const SideButton = () => {
  const { showActionSheetWithOptions } = useActionSheet();
  const cancelButtonIndex = 1;
  const options = ['Email', 'Cancel'];
  const title = 'Email Me';
  const message = 'Let me know your issues';

  return showActionSheetWithOptions(
    {
      options,
      cancelButtonIndex,
      title,
      message,
    },
    (buttonIndex) => {
      if (buttonIndex === 0) {
        Linking.openURL('mailto:_____').catch();
      } else {
        return;
      }
    }
  );
};

Or even how I call it here:

import { Linking, Text, TouchableOpacity, View } from 'react-native';
import { SideButton } from './utils/HelpPopUp';

const ButtonContainer = () => (
  <TouchableOpacity>
    <Text onPress={() => Linking.openURL('_MY_WEBSITE_').catch()}>Checkout my stuff</Text>
  </TouchableOpacity>
);

const Menu = (props) => {
  return (
    <View>
        <ButtonContainer />
    </View>
  );
};

export default Menu;
Etep
  • 2,721
  • 4
  • 17
  • 28

1 Answers1

0

Sorry, my answer would be to suggest an alternative rather than answer your question and present the component I use myself. I did not use the package you mentioned in the topic, but I tried with a different package before, it does the same job. https://www.npmjs.com/package/react-native-actions-sheet

This is the custom component I used.

import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import ActionSheet from 'react-native-actions-sheet';;

const CustomActionSheet = React.forwardRef(({children, title}, ref) => {
  return (
    <ActionSheet
      ref={ref}
      headerAlwaysVisible={true}
      containerStyle={[
        styles.containerStyle,
        {backgroundColor: '#FFF'},
      ]}
      CustomHeaderComponent={
        <View style={[styles.header, {backgroundColor: '#4ac'}]}>
          <Text style={styles.title}>
            {title}
          </Text>
        </View>
      }>
      {children}
    </ActionSheet>
  );
});

const styles = StyleSheet.create({
  header: {
    height: 50,
    justifyContent: 'center',
    padding: 5,
  },
  title: {
    color: '#FFF',
    fontSize: globalStyles.titleText.fontSize,
  },
  containerStyle: {
    borderRadius: 0,
  },
});

export default CustomActionSheet;

Usage:

import React, { createRef } from "react";
import {View, Text} from "react-native";
import CustomActionSheet from './CustomActionSheet';

const actionSheetRef = createRef();

const AnythingPage = () => {
   return (
     <View>
       <Text onPress={() => actionSheetRef.current?.show()}>
         Open Custom Sheet
       </Text>
       
       <CustomActionSheet ref={actionSheetRef} title={'Title'}>
         <View>
           <Text>Add anything in it.</Text>
         </View>
       </CustomActionSheet>
     </View>
   )
}

You can develop a structure that will be used in the whole application by going through these.

HyopeR
  • 387
  • 2
  • 11