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

77
Vistas
Deconstructment assignment notation

I am following this example for creating a blog with Gatsby.

Throughout this tutorial, assignment notation is used like so:

export default function Index({ data }) {

  const { edges: posts } = data.allMarkdownRemark

  return (
    <div className="blog-posts">
      {posts
        .filter(post => post.node.frontmatter.title.length > 0)
        .map(({ node: post }) => {
          return (...);
        })}
    </div>
  )
}

Line 2, which appears to me as deconstructing assignment, is confusing to me. From what dictionary are we assigning the key edges's value posts to? Why are we able to reference posts later on without referencing it using the edges key?

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

0

You've stumbled upon destructuring and assigning to a new variable.

You can find the docs here and the scroll down to Assigning to new variable names.

What it does is that you are giving a declaring a new variable (in your case named posts that has the value of data.allMarkdownRemark.edges.

The syntax may seem backwards as edges is giving value to posts and not the other way around, but I think this makes sense if you think about it a bit.

Having it like this allows you to change from this:

const { edges } = data.allMarkdownRemark

to this:

const { edges: posts } = data.allMarkdownRemark

with minimal changes.

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