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

后端 未结 6 753
悲哀的现实
悲哀的现实 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:19

    I am sure this can help. Create fileA anywhere in the directory and export all the functions.

    export const func1=()=>{
        // do stuff
    }
    export const func2=()=>{
        // do stuff 
    }
    export const func3=()=>{
        // do stuff 
    }
    export const func4=()=>{
        // do stuff 
    }
    export const func5=()=>{
        // do stuff 
    }
    

    Here, in your React component class, you can simply write one import statement.

    import React from 'react';
    import {func1,func2,func3} from 'path_to_fileA';
    
    class HtmlComponents extends React.Component {
        constructor(props){
            super(props);
            this.rippleClickFunction=this.rippleClickFunction.bind(this);
        }
        rippleClickFunction(){
            //do stuff. 
            // foo==bar
            func1(data);
            func2(data)
        }
       render() {
          return (
             

    React Components

    ); } } export default HtmlComponents;

提交回复
热议问题