0

I want to export this keys to app.js but cant do it showing this error :-

'const' can only be used in a .ts file.

ApiKey.js

import React from 'react';

const firebaseConfig;
export default class firekeys extends React.Component {
     const firebaseConfig ={
        apiKey: "key",
          authDomain: "auth",
          databaseURL: "url",
          projectId: "Id",
          storageBucket: "",
          messagingSenderId: "SID"
    }
};

App.js

import React from 'react';
import firekeys from "./constants/ApiKeys"
import * as firebase from 'firebase';
firebase.initializeApp(firekeys.firebaseConfig);
0

2 Answers 2

2

Two issues I see here: 1. You can't redeclare a const. 2. Your are exporting your class, not the const. Furthermore, you should be assigning class properties to your React class, not variables. Below should work but you'll need to import firebaseConfig as a named export.

export const firebaseConfig ={
    apiKey: "key",
      authDomain: "auth",
      databaseURL: "url",
      projectId: "Id",
      storageBucket: "",
      messagingSenderId: "SID"
}

export default class firekeys extends React.Component {

};
Sign up to request clarification or add additional context in comments.

Comments

0

You should rewrite ApiKeys.js as follows, unless you have some specific reason for needing them in a component:

export default firebaseConfig = {
  apiKey: "key",
  authDomain: "auth",
  databaseURL: "url",
  projectId: "Id",
  storageBucket: "",
  messagingSenderId: "SID"
}

import firekeys from "./constants/ApiKeys" (to be fair the variable you name them isn't important)

Then you should be able to access the keys as follows

firekeys.apiKey

You should probably take a look at the different ways to use let, var and const https://medium.com/podiihq/javascript-variables-should-you-use-let-var-or-const-394f7645c88f

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.