Javascript 在React/React Native中配置包
如何在React(一般)中配置包。 在NodeJS中,我们有一个singleton,因此我们可以创建一个外部文件,比如(Javascript 在React/React Native中配置包,javascript,reactjs,react-native,Javascript,Reactjs,React Native,如何在React(一般)中配置包。 在NodeJS中,我们有一个singleton,因此我们可以创建一个外部文件,比如(/firebase config.js),然后将其导入主Index.js文件(节点应用程序的起点) 在react中,到目前为止,我习惯于在Index.html中配置它,但现在我使用的是react native,它没有DOM,因此我无法将配置放在那里 以index.js或app.js(考虑cli版本,其中index.js是根目录,app.js是具有所有其他子目录的直接子目录)为例
/firebase config.js
),然后将其导入主Index.js
文件(节点应用程序的起点)
在react中,到目前为止,我习惯于在Index.html
中配置它,但现在我使用的是react native,它没有DOM,因此我无法将配置放在那里
以index.js
或app.js
(考虑cli版本,其中index.js是根目录,app.js是具有所有其他子目录的直接子目录)为例,我的配置文件夹位于/src/config/flamelink.js
,这是我的配置
import * as firebase from 'firebase';
import flamelink from 'flamelink';
const firebaseConfig = {
apiKey: '<your-api-key>', // required
authDomain: '<your-auth-domain>', // required
databaseURL: '<your-database-url>', // required
projectId: '<your-project-id>', // required
storageBucket: '<your-storage-bucket-code>', // required
messagingSenderId: '<your-messenger-id>' // optional
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
const app = flamelink({ firebaseApp });
从“firebase”导入*作为firebase;
从“flamelink”导入flamelink;
常量firebaseConfig={
apiKey:“”,//必需
authDomain:“”,//必需
数据库URL:“”,//必需
projectId:“”,//必需
storageBucket:“”,//必需
messagingSenderId:“”//可选
};
const firebaseApp=firebase.initializeApp(firebaseConfig);
const-app=flamelink({firebaseApp});
问题:我应该在哪里导入它来配置它?或者它会像node一样响应本机工作,通过导入,一切都会正常工作吗?是的,您可以在firebase config.js中进行配置,例如
const firebaseConfig={
apiKey:“”,//必需
authDomain:“”,//必需
数据库URL:“”,//必需
projectId:“”,//必需
storageBucket:“”,//必需
messagingSenderId:“”//可选
};
导出默认firebaseConfig;
然后呢
从“/firebase config”导入firebaseConfig;
在代码的其他地方