⊗jsrtPmCpChA 83 of 112 menu

Array for creating child components in React

Let's say we have an array with products:

const prods = [ {id: id(), name: 'product1', cost: 100}, {id: id(), name: 'product2', cost: 200}, {id: id(), name: 'product3', cost: 300}, ];

Let's display three Product components, passing them the data from our array as props. We won't use a loop for now, but will simply access the array and object elements:

function App() { return <div> <Product name={prods[0].name} cost={prods[0].cost} /> <Product name={prods[1].name} cost={prods[1].cost} /> <Product name={prods[2].name} cost={prods[2].cost} /> </div>; }

Create a User component that displays user data on the screen. Let this data be first name, last name, age. Format the user data as a tr tag containing three td tags.

In the App component the following array is given:

const users = [ {id: id(), name: 'user1', surn: 'surn1', age: 30}, {id: id(), name: 'user2', surn: 'surn2', age: 31}, {id: id(), name: 'user3', surn: 'surn3', age: 32}, ];

Use this array to output three users. Format their output as a table table.

byenru