GithubHelp home page GithubHelp logo

Comments (5)

JPaul23 avatar JPaul23 commented on June 27, 2024 5

Hello @sumit96367 , after some research this is how I resolved it on my end
In my useFetch.js

import { RAPID_API_KEY } from '@env';
const rapidApiKey = RAPID_API_KEY;

and in my babel.config.js I added this ["module:react-native-dotenv"] in plugin as below:

plugins: [
      "@babel/plugin-proposal-export-namespace-from",
      "react-native-reanimated/plugin",
      require.resolve("expo-router/babel"),
      ["module:react-native-dotenv"],
    ],

Let me know if it works for you.

from project_react_native_jobs.

AlejandroSuero avatar AlejandroSuero commented on June 27, 2024 1

Hello @sumit96367 and everyone else who has this problem,

I've started with react native through JavaScriptMastery this week and I've been getting the same error. And here is my solution.

I added this to my app.json, which I renamed as app.config.js

// app.config.js
import "dotenv/config"

export default {
    // Default app.json
    extra: {
        // Default extra
        rapidApiKey: process.env.RAPID_API_KEY,
        // ...
    }
}

If you don't have dotenv installed:

npm install --save-dev dotenv

Then to call these enviroment variables:

// useFetch.js
// ... imports
import Constants from "expo-constants"

const rapidApiKey = Constants.expoConfig.extra.rapidApiKey
// ...

If you don't have expo-constants installed:

npx expo install expo-constants

from project_react_native_jobs.

adewale2018 avatar adewale2018 commented on June 27, 2024 1

Hello @sumit96367 and everyone else who has this problem,

I've started with react native through JavaScriptMastery this week and I've been getting the same error. And here is my solution.

I added this to my app.json, which I renamed as app.config.js

// app.config.js
import "dotenv/config"

export default {
    // Default app.json
    extra: {
        // Default extra
        rapidApiKey: process.env.RAPID_API_KEY,
        // ...
    }
}

If you don't have dotenv installed:

npm install --save-dev dotenv

Then to call these enviroment variables:

// useFetch.js
// ... imports
import Constants from "expo-constants"

const rapidApiKey = Constants.expoConfig.extra.rapidApiKey
// ...

If you don't have expo-constants installed:

npx expo install expo-constants

Thank you for this solution. This is my first time of learning react-native.

from project_react_native_jobs.

JatinBisht2308 avatar JatinBisht2308 commented on June 27, 2024

@JPaul23 @sumit96367 @adrianhajdin
After that, it will give and error like react-native-dotenv module not found so download the react-native-dotenv module.
npm install react-native-dotenv
Then it will work.

from project_react_native_jobs.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.