Junior Chang
Junior Chang

Reputation: 65

setting up .env in react native

Im trying to set up my env in react-native. I have install "react-native-dotenv": "^3.3.1".

In my babel.config.js I have the following:

  presets: ["module:metro-react-native-babel-preset"],
  plugins: [
    [
      "module:react-native-dotenv",
      {
        moduleName: "@env",
        path: ".env",
        blacklist: null,
        whitelist: null,
        safe: false,
        allowUndefined: false,
      },
    ],
  ],
};

I have a .env file in my root directory, inside i have

TEST_API = 123

in my file that I want to use the env, I imported it like this:

import {TEST_API}

when I try to use it {TEST_API} it does not work.

Upvotes: 0

Views: 1009

Answers (1)

Yamisleidy Muñoz
Yamisleidy Muñoz

Reputation: 111

Try with this one:

import {TEST_API} from '@env';

Upvotes: 1

Related Questions