skip to Main Content

I am having trouble using react-native-config in my React Native app. Here’s my code:

app.js

import Config from 'react-native-config';
console.log(Config);

.env

SECRET_KEY="kndlknv94ii4rpp"

The console.log statement in app.js returns an empty object. What am I doing wrong?

API keys should return on Config.SECRET_KEY but Config object itself returns an empty object

2

Answers


  1. I believe it’s because of your env file format. As in the doc example, they are not using quotation marks. This might be a solution.

    Login or Signup to reply.
  2. Create a new file .env in the root of your React Native app:

    API_URL=https://myapi.com
    GOOGLE_MAPS_API_KEY=abcdefgh
    

    Then access variables defined there from your app:

    import Config from "react-native-config";
    
    Config.API_URL; // 'https://myapi.com'
    Config.GOOGLE_MAPS_API_KEY; // 'abcdefgh'
    

    Documentation here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search