I am currently learning react and I am confused about mapping components/props. While I generally understand the concepts one thing that is challenging me right now is understanding naming conventions for {props.xxx.dataname} I don't understand the naming convention and how the xxx part is called. Sometimes it can be called item or product and it is never declared in the code itself anywhere. This example i listed is stumping me and I don't understand how item registers as anything when it has not been declared.
Please explain this to me, especially this code here "item={item}". Item is never declared so how does this code know to find "Item" from the 3rd code snippet holding the data.
Also how come in the 4th code snippet "product" can be used instead of "item"?
import React from "react"
function Product(props) {
return (
<div>
<h2>{props.product.name}</h2>
<p>{props.product.price.toLocaleString("en-US", { style: "currency", currency: "USD" })} - {props.product.description}</p>
</div>
)
}
export default Product
import React from "react"
function TodoItem(props) {
return (
<div className="todo-item">
<input type="checkbox" checked={props.item.completed}/>
<p>{props.item.text}</p>
</div>
)
}
export default TodoItem
import React from "react"
import TodoItem from "./TodoItem"
import todosData from "./todosData"
function App() {
const todoItems = todosData.map(item => <TodoItem key={item.id} item={item}/>)
return (
<div className="todo-list">
{todoItems}
</div>
)
}
export default App
const todosData = [
{
id: 1,
text: "Take out the trash",
completed: true
},
{
id: 2,
text: "Grocery shopping",
completed: false
},
{
id: 3,
text: "Clean gecko tank",
completed: false
},
{
id: 4,
text: "Mow lawn",
completed: true
},
{
id: 5,
text: "Catch up on Arrested Development",
completed: false
}
]
export default todosData