Home > Software engineering >  How use a function from another file in react native
How use a function from another file in react native

Time:05-25

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.

CodePudding user response:

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

//In Settings.json
import getTempBucketData  from 'Home.js';

let varName = getTempBucketData();

CodePudding user response:

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

  • Related