zoukankan      html  css  js  c++  java
  • [React] Use Environment Variables with Create React App

    Environment variables are a standard way to configure variables in your app based on the current environment (development, test, production). This lesson explores how to use environment variables specifically with Create React App, starting with the built in NODE_ENV variable, as well as how to create custom environment variables for your app.

     .env: 
    REACT_APP_CUSTOM=<custom_value_in_dotenv_file>

    It must start with "REACT_APP_", otherwise, it doesn't work;

    Inside component, we can do:

        <div className="App">
          <pre>process.env.NODE_ENV: {process.env.NODE_ENV}</pre>
          <pre>process.env.REACT_APP_CUSTOM: {process.env.REACT_APP_CUSTOM}</pre>
        </div>

    It is recommended to push .env file to git, so can share with team.

    And always you can overwrite with .env.local file

    REACT_APP_CUSTOM=<custom_value_in_dotenv_file>
  • 相关阅读:
    [BZOJ1006]神奇的国度
    配置ubuntu18.04
    数据库的基本操作
    关于排序的算法——桶排序
    关于TCP/IP协议的记录
    laravel学习历程
    装箱问题
    01背包
    数字三角形
    统计单词的个数
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13028874.html
Copyright © 2011-2022 走看看