How can I create Global Helper functions in react-native
?
I would like to use for accessing sqlite
database or fetching data from server. Can I create a JavaScript
file with functions and call that functions from multiple views?
global variable
class MainActivity extends Component {
constructor(){
super();
// Creating Global Variable.
global.SampleVar = 'This is Global Variable.';
}
}
in second activity
class SecondActivity extends Component {
render(){
return(
<View>
<Text> {global.SampleVar} </Text>
</View>
);
}
}
But if you want to have a global function
export function TestFunc1() {
}
export function TestFunc2() {
}
Then import and use
import { TestFunc1 } from './path_to_file'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With