How to create helper file full of functions in react native?

后端 未结 6 734
悲哀的现实
悲哀的现实 2020-12-04 06:48

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

6条回答
  •  有刺的猬
    2020-12-04 07:29

    Quick note: You are importing a class, you can't call properties on a class unless they are static properties. Read more about classes here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

    There's an easy way to do this, though. If you are making helper functions, you should instead make a file that exports functions like this:

    export function HelloChandu() {
    
    }
    
    export function HelloTester() {
    
    }
    

    Then import them like so:

    import { HelloChandu } from './helpers'

    or...

    import functions from './helpers' then functions.HelloChandu

提交回复
热议问题