0

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 Answers2

0

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.

0

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.

Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34