如何调用/执行一个函数从另一个组件在反应本机? [英] How do I call/execute a function from another component in react native?

查看:164
本文介绍了如何调用/执行一个函数从另一个组件在反应本机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在本机中调​​用当前组件中的其他组件功能?他们都在不同的脚本。

How do I call other component function in my current component in react native? They are both in different script as well.

任何人都知道如何在反应本地做这个事情?

Anyone know how to do this in react native?

//ClassOne.js
class ClassOne extends React.Component {

    constructor(props) {
        super(props);
    }

    setValue(){
    }
}

//ClassTwo.js
class ClassTwo extends React.Component {

    constructor(props) {
        super(props);   
    }

    callSetValue(){
        ClassOne.setValue(); HOW???
    }
}


推荐答案

您想要调用的函数是static,您必须在要调用该函数的范围内实例化所需的任何类。在ClassTwo中说你想在ClassOne中调用一个方法...实例化ClassTwo内的ClassOne实例,然后使用该对象调用该函数。

Unless the function you are wanting to call is static you must instantiate whatever class you want inside the scope of where you want to call the function. Say in ClassTwo you want to call a method in ClassOne... Instantiate an instance of ClassOne inside of ClassTwo and then call the function using that object.

这篇关于如何调用/执行一个函数从另一个组件在反应本机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆