Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

71
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda