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

205
Vistas
React JS Unexpected reserved word 'await'

I am struggling with this async await issue I have created async function and for that I am calling await but I am getting error Unexpected reserved word 'await' Below is the async function

export const addProductCall = async (product) => {
    let accessToken = window.localStorage.getItem("accessToken");
    await axios.post(SERVER_URI + '/inventoryservice/v1/item',
        product,
        { headers: { "Authorization": "Bearer " + accessToken, "Content-Type": "application/json" } })
}

Below is the function from where I am calling this function.

const handleSubmit = () => {
        const data = {
            'storeId': customerDetails.id, category, categoryToBeAdded, description,
            productCode, productName, sku, price, unit, quantity
        }
        await addProductCall(data);
    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You cannot use the await keyword outside of an async function :

const handleSubmit = () => {
  const data = {
    'storeId': customerDetails.id, category, categoryToBeAdded, description,
      productCode, productName, sku, price, unit, quantity
  }
  await addProductCall(data);
}

should be :

const handleSubmit = async () => {
  const data = {
    'storeId': customerDetails.id, category, categoryToBeAdded, description,
      productCode, productName, sku, price, unit, quantity
  }
  await addProductCall(data);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Replace

const handleSubmit = () => {
     

with

const handleSubmit = async () => {
     

For await to work, it needs to be wrapped inside an async function

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