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

208
Vistas
Destructuring in React props, don't understand {...{ [resourceName]: item }} inside props

I came cross this code, and I don't understand {...{ [resourceName]: item }} inside the props inside the RegularList.js file.

I have two questions:

  1. Whouldn't we, syntaxwise, write sth.=sth.
  2. Which object is this {...{ [resourceName]: item }} trying to copy here?

Here's my code:

RegularList.js

export const RegularList = ({
  items,
  resourceName,
  itemComponent: ItemComponent,
}) => {
  return (
    <>
      {items.map((item, i) => (
        <ItemComponent key={i} {...{ [resourceName]: item }} />
      ))}
    </>
  );
};

App.js

const products = [{
    name: 'Flat-Screen TV',
    price: '$300',
    description: 'Huge LCD screen, a great deal',
    rating: 4.5,
}, {
    name: 'Basketball',
    price: '$10',
    description: 'Just like the pros use',
    rating: 3.8,
}, {
    name: 'Running Shoes',
    price: '$120',
    description: 'State-of-the-art technology for optimum running',
    rating: 4.2,
}];


    <RegularList
            items={products}
            resourceName="product"
            itemComponent={SmallProductListItem} />

SmallProductListItem.js

export const SmallProductListItem = ({ product }) => {
    const { name, price } = product;

    return (
        <h3>{name} - {price}</h3>
    );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

{ [resourceName]: item }

Is creating a new Object with a dynamic key resourceName

...{}

Is spread operator.

So what is achieve here, is you pass a dynamic prop resourceName to your component.

For example, if resourceName === "foo" your ItemComponent will have the prop foo:

<ItemComponent foo={item} />
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