Skip To Main Content

Spreading with React

Today I was learning more React. The key thing I want to remember is the potential use of the spread operator when passing props.

Instead of:

<Card
  key={card.id}
  title={card.title}
  content={card.content}
>

You can pass all the props at once like this:

<Card
  key={card.id}
  data={card}
>

OR you can spread the props out:

<Card
  key={card.id}
  {...card}
>
categories:Uncategorized