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

165
Visualizações
what is the purpose of these props?

I'm trying to learn React from existing code, in the props section there is code like this

const {
  products,
  productDetail = {product:{}, productColor:[] },
  location={},
  history
 } = props

I don't understand on the productDetail and location, why is there {product:{}, productColor:[] }, what is the purpose of that?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

These are some default values for the specified props. Looking at the provided example, I can say that history and products are required - when someone tries to render the component, he is obliged to procide that information.

However, the productDetails and location have default values so they are optional. The person trying to render this component may provide some values (if he wants to) but he is not obliged to do so.

about 4 years ago · Juan Pablo Isaza Relatório

0

Essentially what you have here is nothing more than a declaration of a variable (and assigning given by the object 'props'). Instead of the code posted one could write:

const productDetail = {product:{}, productColor:[] }

productDetail is a variable. A variable that happens to be an object. This object contains two values, one named product that itself is defined as another object (hence why the '{}' is there) and productColor which is an array as the '[]' indicate.

Same with location. The "type" is array and the default value of that variable is an empty array.

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