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

148
Vistas
¿Cómo usar el resultado de la consulta "fuera" de React with RTK Query?

Tengo una definición de API con este y otro punto final:

 ... saveCaptionsByLang: builder.mutation< Transcript, { wbId: string; ytUrl: string; lang: SupportedLang } >({ query: ({ wbId, ytUrl, lang }) => ({ url: wbId, params: { ytId: getYoutubeVideoId(ytUrl), toLang: lang, }, }) }), ...

Y quiero poder usar esto afuera para crear una función que pueda llamar a esta función en función de los valores en una matriz.

Por ejemplo:

 export async function saveCaptionsInAllLangs(wbId: string, ytUrl: string) { return Promise.all(["en", "fr", "pt", "es"].map(saveCaption)); async function saveCaption(lang: SupportedLang) { return await singleRequestFunction(..., lang).then(res =>...); //do something with the res // The awaited func here would be the equivalent of saveCaptionsByLang but without RTK Query } }

Y esto es lo que tengo ahora:

 export async function saveCaptionsInAllLangs(wbId: string, ytUrl: string) { return Promise.all(["en", "fr", "pt", "es"].map(saveCaption)); async function saveCaption(lang: SupportedLang) { const res = store.dispatch( apiSvc.endpoints.saveCaptionsByLang.initiate({ wbId, ytUrl, lang, }) ); } }

La variable res del fragmento de código final dice que es del siguiente tipo,

 { data: FooType; } | { error: FetchBaseQueryError | SerializedError; }

pero no puedo acceder a los .data de la variable porque dice que no existe.

about 4 years ago · Juan Pablo Isaza
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