Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
React - JS not storing object in global

I am trying to insert an object (user) into a global so i can refer back to it without having to do numerous api-calls when needed.

The data is being grabbed from the service fine, however it is not getting stored

The code:


  useEffect(()=>{
    // this needs to be here because the user doesnt exist on first render
    if (user){
      fetch (`${window.ipAddress.ip}/User/getByEmail`,{
        method: "POST",  
        headers:{'Content-Type':'application/json'},
        body: JSON.stringify({ email: user.email }) 
      })
      .then(res=>res.json())
      .catch(error =>{ 
        setErrorVal(true);
        console.log("error: " + error);
      })
      .then((result)=>{
          console.log(result) // this prints appropriately
          window.BackendUser = { result } // this isnt being set for some reason
          setExecutedFetch(true);
      })
    }
},[isAuthenticated])

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can not write brackets around your result, bracketing is JSX syntax.

window.BackendUser = result 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!