Answer the question
In order to leave comments, you need to log in
How do you change localhost to the server name in a React app?
There are such sections of code in the React application where localhost is registered, for example
export const getData = () => {
return fetch("http://localhost:3000/data.json", {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
})
.then((response) => response.json())
.catch((error) => {
throw error;
});
};
Answer the question
In order to leave comments, you need to log in
You can specify a relative path without hostname.
You can get the current server address from window.location
. You can substitute it at the application build stage through environment variables in webpack or react.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question