Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!