1

In my project, I use axios for API. And I hardcoded these API links in my code. So I want to remove hardcoding and set env variables. But I want such a setting that automatically considers the current environment that we are in prod env or dev env and sets API URL as per the current environment.

axios.get("https://jsonplaceholder.typicode.com/posts").then(response => {

            this.setState({ fetchData: response.data });
        });

above API URL I use only to ask the question.

  • https://www.npmjs.com/package/react-app-env Can use this module – Germa Vinsmoke Jan 09 '21 at 08:24
  • https://stackoverflow.com/questions/49579028/adding-an-env-file-to-react-project – A.R.SEIF Jan 09 '21 at 08:25
  • @GermaVinsmoke How can I use the react-app-env library easily in my app if I want dev and prod environments and only for API changes for both environments? –  Jan 09 '21 at 11:12

0 Answers0