forked from academind/react-typescript-course-resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.tsx
39 lines (35 loc) · 826 Bytes
/
Card.tsx
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
// Example: A Card component that has multiple "slots" for content
// Main slot => children prop
// Actions slot => actions prop
import { ReactNode } from 'react';
type CardProps = {
title: string;
children: ReactNode;
// "actions" is like an extra "slot" of this component
// It's the same type as the children prop, since we expect JSX code as a prop value
actions: ReactNode;
};
export function Card({ title, children, actions }: CardProps) {
return (
<section>
<h2>{title}</h2>
{children}
{actions}
</section>
);
}
// Example Usage:
export function Demo() {
return (
<Card
title="My Card"
actions={
<button onClick={() => console.log('Button clicked!')}>
Click Me!
</button>
}
>
<p>Some content</p>
</Card>
);
}