Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
Convert value from promise to string (cookieStore.get question)

I'm attempting to fetch a part of a value from a cookie on a website. So I've written code to get the cookie value, that works fine. And I attempted to do a JSON.stringify() of the returned value into a string, but instead it converts it into an empty object. I suspect this is because the returned object is a Promise object but I don't know why that would make a difference. Here is what I've done so far.

const getCookie = async (name) => {
  const cookie = await cookieStore.get(name);
  if(cookie) {return cookie.value}
  else {console.log('cookie not found')}
}
const cookievalue = getCookie('foo');

And this returns:

Promise {<fulfilled>: 'locale%3Des_us'}

Which is in fact the cookie value that I want. But if I then run:

const newcookievalue = JSON.stringify(cookievalue);

I get:

'[object Promise]'

What I'm trying to do, by the way, is to run an IF statement on that value--if it's "es_us" do one thing, if it's "en_us" do another thing. So for right now the IF statement in place on getCookie is really just testing in the console that I can get and convert the value to a string, before I put the code in my application.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To get a value form an async function you should use await keyword. like this:

 const cookievalue = await getCookie('foo');
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda