Component Props in NextJS

In NextJS, just like in React, data from parent components to child components can be passed through props.

Let's see how this is done in practice. Let our child component be able to accept props:

src/comp/child/child.jsxexport default function Child({text1, text2}) {
  return <p>
    child
  </p>;
}

Let's display them in the component's markup:

src/comp/child/child.jsxexport default function Child({text1, text2}) {
  return <p>
    child
    {text1}
    {text2}
  </p>;
}

Let our child component be imported in the parent component:

src/app/test/page.jsximport Child from '@/comp/child/child.jsx';

export default function Test() {
  return <>
    <h1>Test</h1>
    <Child />
  </>;
}

Let's pass data from the parent component to the child component:

src/app/test/page.jsximport Child from '@/comp/child/child.jsx';

export default function Test() {
  return <>
    <h1>Test</h1>
    <Child text1="aaa" text2="bbb" />
  </>;
}
Задание 1

Create a child component Product for displaying a product. Let the product name and price be passed via props.

Задание 2

Given the following array of products:

prods.jslet prods = [
  {
    id: 1,
    name: 'prod1',
    cost: 100,
  },
  {
    id: 2,
    name: 'prod2',
    cost: 200,
  },
  {
    id: 3,
    name: 'prod3',
    cost: 300,
  },
];

Display the product data in a loop, using the child component Product.