DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Pass props using spread operator

const cardProps = { title: "Card Title", content: "Hello  World" };

const App = () => {
  return (
    <Card
      title={cardProps.title}
      content={cardProps.content}
    />
  );
};
Enter fullscreen mode Exit fullscreen mode

Simpler way to do this:

const cardProps = { title: "Card Title", content: "Hello  World" };

const App = () => {
  return <Card {...cardProps} />;
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)