如何在React Native中从其他JS文件调用函数?

Kev*_*ali 5 javascript react-native

所以我有一个使用“react-native-off-canvas-menu”的 Drawer.Js,其唯一目的是打开和关闭抽屉。问题是这个抽屉只能通过手势(向左/向右滑动)打开和关闭。我想用一个按钮绑定这个打开和关闭功能。问题是当我尝试从 Home.Js 调用函数 handleClick 到我的 Drawer.Js 时,它显示错误

在我的 Drawer.Js 里面

class FirstScreen extends Component {

constructor(props) {
super(props);
this.state = {
  menuOpen: false
};
this.handleClick = this.handleMenu.bind(this);
}

handleMenu() {
 const { menuOpen } = this.state;
 this.setState({
  menuOpen: !menuOpen
  });
  }
  // Some Render Method Where i tried to create a button, and calling 
     this.handleMenu() on the onPress event, and it's successful

  *//After the Render Method

   export function a() {
    return this.handleClick();
    }
Run Code Online (Sandbox Code Playgroud)

我还使用 React Native Router Flux,我的应用程序的第一条路线是 Home.js,在 Home.js 中我将放置一个按钮来触发抽屉打开。

这是我的 Home.js 代码 *//Some Import

   import { a } from './Drawer';

 class Home extends Component {

    constructor(props) {
     super(props);
      this.handleKlik = this.handleKlik.bind(this);
     }

     handleKlik() {
        a();
      }

     *// Render Method Start
      <View>
         <TouchableOpacity onPress={() => this.handleKlik()}>
            <View style={styles.btnContainer}>
             <Text style={styles.btnText}>{'Toggle'.toUpperCase()}
             </Text>
           </View>
         </TouchableOpacity>
      <View>
Run Code Online (Sandbox Code Playgroud)

在 Home.js 中,当我尝试单击按钮时,我收到了类似“未定义不是函数(评估“this.handleClick”)”的错误。

好吧,我想我知道我的导出功能可能是问题所在。谁能详细说明我该如何解决这个问题?我已阅读本教程,但我似乎无法理解为什么在我的项目中的另一个 Js 文件中调用函数如此困难