0

.env

REACT_APP_API_URL=http://localhost:8080

react file

    export const signupfetch=user=>{
    
    return fetch(`process.env.REACT_APP_API_URL`,{
       method:"POST",
       
       headers:{
           Accept:"application/json",
           "Content-Type":"application/json"
       },
       body:JSON.stringify(user)
   }).then(response=>{return response.json()})
   .catch(err=>console.log(err))
};
enter code here

REACT_APP_API_UR is returning data undefind for all the urls

  • 1
    Does this answer your question? [react evironment variables .env return undefined](https://stackoverflow.com/questions/53237293/react-evironment-variables-env-return-undefined) – Bagata Apr 23 '21 at 13:57

1 Answers1

0

I believe the problem happened because you converted process.env.REACT_APP_API_URL into a string and are trying to fetch it.

You shouldn't use the grave accent, or any apostrophe, around it. So simply remove the `` and try running like this:

return fetch(process.env.REACT_APP_API_URL,{
       method:"POST",