Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!