Home > Mobile >  React semicolon missing
React semicolon missing

Time:06-27

export async function getStaticProps() {
  const propertyForSale = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-sale&hitsPerPage=6`);
  const propertyForRent = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-rent&hitsPerPage=6`);

  return
  {
    props: {
     propertiesForSale: propertyForSale?.hits,
     propertiesForRent: propertyForRent?.hits, 
    }
  }
}

When writing this I getting a missing semicolon error. What should I do?

CodePudding user response:

I did some modifications in order to test your code and it seems that breaking a line after the return statement is causing your error.

function getStaticProps() {
  const propertyForSale = {hits: ['Property Sale']};
  const propertyForRent = {hits: ['Property Rent']};

  return {
    props: {
     propertiesForSale: propertyForSale?.hits,
     propertiesForRent: propertyForRent?.hits, 
    }
  }
}

console.log(getStaticProps().props)

Same snipped, but with error

function getStaticProps() {
  const propertyForSale = {hits: ['Property Sale']};
  const propertyForRent = {hits: ['Property Rent']};

  return
    {
    props: {
     propertiesForSale: propertyForSale?.hits,
     propertiesForRent: propertyForRent?.hits, 
    }
  }
}

console.log(getStaticProps().props)

CodePudding user response:

Try this:

export async function getStaticProps() {
  const propertyForSale = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-sale&hitsPerPage=6`);
  const propertyForRent = await fetchApi(`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-rent&hitsPerPage=6`);

  return
  (
    props: {
     propertiesForSale: propertyForSale?.hits,
     propertiesForRent: propertyForRent?.hits, 
    }
  )
}
  • Related