React - JS ไม่จัดเก็บวัตถุใน global


  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])

window.BackendUser = result