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

166
Vistas
How do I load an Alpine Store with asynchronous values from a fetch call?

Trying to load an Alpine store with values (a list of arrays) from an API call. The fetch returns a promise, so looking for the best way to load this diretly:

document.addEventListener('alpine:init', () => {
    Alpine.store('myStore', {
        my_data: fetch('/api/1')
        .then(response => response.json())
    })
})

I’m not committed to fetch but whatever’s easiest to add to the store directly.

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

0

Invert it. Fetch the data first then create the store once it's resolved

document.addEventListener("alpine:init", async () => {
  const res = await fetch("/api/1");
  if (!res.ok) {
    throw new Error(`${res.status}: ${await res.text()}`);
  }
  Alpine.store("myStore", {
    my_data: await res.json(),
  });
});
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