Prop Drilling
- React data can only pass data down
- Code deployed in netlify
- getDetails method in parent component is called on click of button from child component
import React from "react";
import { cricketData } from "./CricketData";
const Cricketers = () => {
const getDetails = (id) => {
let cricketDetailById = cricketData.find((data) => data.id === id).details;
console.log(cricketDetailById);
};
return (
<>
{cricketData.map((data) => {
//return ;
return ;
})}
>
);
};
const Cricketer = (props) => {
//const { name, category } = props.cricket;
const { name, category, id, getDetails } = props;
console.log(props);
return (
- {name}
- {category}
);
};
export default Cricketers;
DATA
export const cricketData = [
{
id: 1,
name: "SKY",
category: "AllRounder",
details: "He is MR 360",
},
{
id: 2,
name: "Ishan Kishan",
category: "Batsman",
details: "Explosive batsman with a double century",
},
{
id: 3,
name: "Siraj",
category: "Bowler",
details: "fast bowler from Hyderabad",
},
];