Estoy tratando de insertar un objeto (usuario) en un global para poder consultarlo sin tener que hacer numerosas llamadas api cuando sea necesario.
Los datos se obtienen del servicio bien, sin embargo, no se almacenan
El código:
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])No puede escribir corchetes alrededor de su resultado, el corchete es sintaxis JSX.
window.BackendUser = result