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

128
Vistas
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 Respuestas
Responde la pregunta

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 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