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
Axios getPosts error: Unexpected token, expected "," (25:4)

I am trying to get an axios getPosts to work. I am getting a syntax error but I can't find what's wrong with my code.

getPosts = async () => {
    let data = await api.get('/').then(({ data })
    => data);
    this.setState({ posts: data })
  }

The error is posted below:

./src/App.js
SyntaxError: /home/roxx/Documents/eternal_kings_web_app/Twitter-Clone/src/App.js: Unexpected token, expected "," (25:4)

  23 |   getPosts = async () => {
  24 |     let data = await api.get('/').then(({ data })
> 25 |     => data);
     |     ^
  26 |     this.setState({ posts: data })
  27 |   }

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

0

The source of your syntax error is the newline in your arrow function.

Per MDN on Arrow Functions: "Multiline statements require body braces and return." To stick with the one-line:

let data = await api.get("/").then(({ data }) => data);

And to include the desired setState:

let data = await api.get("/").then(({ data }) => this.setState({ posts: data }));
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