reactjs - How to create helper file full of functions in react native? -
though there similar question failing create file multiple functions. not sure if method outdated or not rn evolving fast. how create global helper function in react native?
i new react native.
what want create js file full of many reusable functions , import in components , call there.
what have been doing far might stupid know ask here are.
i tried creating class name chandu , export this
'use strict'; import react, { component } 'react'; import { appregistry, text, textinput, view } 'react-native'; export default class chandu extends component { constructor(props){ super(props); this.papoy = { : 'aaa' }, this.hellobandu = function(){ console.log('hello bandu'); }, } hellochandu(){ console.log('hello chandu'); } }
and import in required component.
import chandu './chandu';
and call
console.log(chandu); console.log(chandu.hellochandu); console.log(chandu.hellobandu); console.log(chandu.papoy);
the thing worked first console.log, means i'm importing correct path, not others.
what correct way please?
quick note: importing class, can't call properties on class unless static properties. read more classes here: https://developer.mozilla.org/en-us/docs/web/javascript/reference/classes
there's easy way this, though. if making helper functions, should instead make file exports functions this:
export function hellochandu() { } export function hellotester() { }
then import them so:
import { hellochandu } './helpers'
Comments
Post a Comment