-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTurtle.jsx
47 lines (40 loc) · 1.55 KB
/
Turtle.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Way #1: Basic props approach - accessing everything through props object
const Turtle = (props) => {
console.log('Turtle data:', JSON.stringify(props.turtle, null, 2));
console.log('Status data:', JSON.stringify(props.status, null, 2));
return (
<div className='turtle' style={{ backgroundColor: props.turtle.color }}>
<h2>{props.turtle.name}</h2>
<p>Color: {props.turtle.color}</p>
<p>Status: {props.status[props.turtle.name]}</p>
</div>
);
};
// // Way #2: Destructuring props in the function body
// const Turtle = (props) => {
// // Extract specific values from props object
// const { turtle, status } = props;
// console.log('Turtle data:', JSON.stringify(turtle, null, 2));
// console.log('Status data:', JSON.stringify(status, null, 2));
// return (
// <div className='turtle' style={{ backgroundColor: turtle.color }}>
// <h2>{turtle.name}</h2>
// <p>Color: {turtle.color}</p>
// <p>Status: {status[turtle.name]}</p>
// </div>
// );
// };
// // Way #3: Destructuring props directly in the function parameters
// const Turtle = ({ turtle, status }) => {
// // Props are immediately broken into named variables
// console.log('Turtle data:', JSON.stringify(turtle, null, 2));
// console.log('Status data:', JSON.stringify(status, null, 2));
// return (
// <div className='turtle' style={{ backgroundColor: turtle.color }}>
// <h2>{turtle.name}</h2>
// <p>Color: {turtle.color}</p>
// <p>Status: {status[turtle.name]}</p>
// </div>
// );
// };
export default Turtle;