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

125
Visualizações
Is there a way to destructure with spreader?

Here were the props I originally tried to pass through to a component:

const allprops = {
    mainprops:{mainprops}, // object
    pageid:{pageId}, // variable
    setpageid:{setPageId}, // state function
    makerefresh:{makeRefresh} // state function
}

<Navbar allprops={allprops} />

I quickly realized I created a monster -- some nested object:

{mainprops: {…}, pageid: {…}, setpageid: {…}, makerefresh: {…}}

 mainprops: {mainprops: {…}}

after breaking my head, I came up with this:

const Navbar = (props) => {
  const {allprops} = props;

  const {mainprops, ...userprops} = allprops
  const {mainprops:{} = {}} = mainprops;
  const {userprops:{} = {}} = userprops;

is there a way to turn this into a one liner? Or a loop or something faster/shorter?

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

0

You are unnecessarily nesting your prop values inside an additional object. This:

const allprops = {
    mainprops:{mainprops}, // object
    pageid:{pageId}, // variable
    setpageid:{setPageId}, // state function
    makerefresh:{makeRefresh} // state function
}

can be made much more concise and easy to work with by changing it to:

const allprops = {
    mainprops,
    pageId,
    setPageId,
    makeRefresh
};

and by spreading that:

<Navbar {...allprops} />

And then in your child component, all you need is:

const Navbar = ({ mainprops, pageId, setPageId, makeRefresh }) => {
  // proceed to use mainprops, pageId, setPageId, makeRefresh
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