如何使用React Native中另一个文件的函数

发布于 2025-01-31 12:44:16 字数 140 浏览 5 评论 0原文

我需要在file home.js,在file settings.js中使用函数。我正在使用功能组件。我需要使用函数const getTempBucketData =()=> {}在settings.js中从home.js获取数据。

I need to use a function from file Home.js , in file Settings.js. I'm using functional components. I need to use the function const getTempBucketData = () => {} that fetch data from Home.js, in Settings.js.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你没皮卡萌 2025-02-07 12:44:16
// Home.js
export const getTempBucketData = () => {}

// Settings.js
import { getTempBucketData } from './Home';

const data = getTempBucketData();
// Home.js
export const getTempBucketData = () => {}

// Settings.js
import { getTempBucketData } from './Home';

const data = getTempBucketData();
慕烟庭风 2025-02-07 12:44:16

您应该使用所需功能编写导出关键字,然后只需使用导入而导入该特定功能
例如:

    // in Settings.js file
     export const funcName = () => {
           //logic here 
    }
    //in Home.js file
    import {funcName } from './appropriatePath/Settings'

现在您可以合法地在此文件中使用此funcname

you should write the export keyword with the required function and then simply import that particular function using the import
for instance:

    // in Settings.js file
     export const funcName = () => {
           //logic here 
    }
    //in Home.js file
    import {funcName } from './appropriatePath/Settings'

now you can use this funcName in this file legally

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文