0

我创建了一个.env文件并安装了“react-native-config”包,但不显示变量值(在 ios 上)。

你能帮我解决这个问题吗?

谢谢

终端 :

 LOG  Running "myRecipes" with {"rootTag":51,"initialProps":{}}
 LOG  ALL RECIPES ===> []
 LOG  -------------> undefined
 LOG  Error in getAllRecipes:  [Error: Cannot load an empty url]

.env

ENV=dev
const URL_API=https://api.spoonacular.com/recipes/complexSearch
const API_KEY=2asjioezarnfzeopa
const MAX_PER_PAGE=30

应用程序.js

import { useDispatch } from "react-redux"
import axios from "axios"
import Config from "react-native-config"
 
import { addRecipes } from "../../redux/actions"
 
export const useFetchRecipes = () => {
  const dispatch = useDispatch()
 
  const getAllRecipes = async () => {
    console.log('------------->',Config.API_KEY);
    ...
  }
 
  return {
    getAllRecipes
  }
}
4

1 回答 1

0
The issue is in your .env file, remove the constant declaration as shown following:

    ENV=dev

    URL_API=https://api.spoonacular.com/recipes/complexSearch
    API_KEY=2asjioezarnfzeopa
    MAX_PER_PAGE=30
于 2022-03-01T14:55:10.413 回答