虽然有一个类似的问题,但我无法创建具有多个函数的文件.不确定这种方法是否已经过时,因为RN的发展非常快.How to create global helper function in react native?
我是个新来的本地人.
我想做的是创建一个包含许多可重用函数的js文件,然后将其导入到组件中并从那里调用它.
到目前为止,我一直在做的事情可能看起来很愚蠢,但我知道你会要求的,所以他们就在这里.
我试着创建一个类名Chandu,然后像这样导出它
'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');
}
}
然后我将其导入任何必需的组件中.
import Chandu from './chandu';
然后像这样称呼它
console.log(Chandu);
console.log(Chandu.helloChandu);
console.log(Chandu.helloBandu);
console.log(Chandu.papoy);
唯一有效的是第一台控制台.日志(log),这意味着我正在导入正确的路径,但没有导入任何其他路径.
请问正确的方法是什么?