Though there is a similar question I am failing to create a file with multiple functions. Not sure if the method is already outdated or not as RN is evolving very fast. How to create global helper function in react native?
I am new to React Native.
What I want to do is to create a js file full of many reusable functions and then import it in components and call it from there.
What I have been doing so far might look stupid but I know you will ask for it so here they are.
I tried creating a class name Chandu and export it like this
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
Text,
TextInput,
View
} from 'react-native';
export default class Chandu extends Component {
constructor(props){
super(props);
this.papoy = {
a : 'aaa'
},
this.helloBandu = function(){
console.log('Hello Bandu');
},
}
helloChandu(){
console.log('Hello Chandu');
}
}
And then I import it in any required Component.
import Chandu from './chandu';
And then call it like this
console.log(Chandu);
console.log(Chandu.helloChandu);
console.log(Chandu.helloBandu);
console.log(Chandu.papoy);
The only thing that worked was the first console.log, which means that I'm importing the correct path, but not any others.
What is the correct way to do this please?