Demo of components with children and other props

This commit is contained in:
Imbus 2024-03-06 11:14:57 +01:00
parent 43afae5d77
commit dcd9879d8d
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/**
* The shape of a task
*/
interface Task {
id: number;
name: string;
}
/**
* The props for the TaskList component
*/
interface TaskProps {
tasks: Task[];
}
/**
* A simple list of tasks
* @param props - The tasks to display
* @returns {JSX.Element} The task list
* @example
* const tasks = [{ id: 1, name: "Do the thing" }];
* return <TaskList tasks={tasks} />;
*/
export function TaskList(props: TaskProps): JSX.Element {
return (
<div>
<h1>Task List</h1>
<p>Tasks go here</p>
<ul>
{props.tasks.map((task) => (
<li key={task.id}>{task.name}</li>
))}
</ul>
</div>
);
}

View file

@ -0,0 +1,24 @@
import { ReactNode } from "react";
/** The props for the container */
interface ContainerProps {
children: ReactNode;
}
/**
* Contains children
* @param props - The children to contain
* @returns {JSX.Element} The container
*/
export function Container(props: ContainerProps): JSX.Element {
return <div>{props.children}</div>;
}
/**
* Contains even more children
* @param props
* @returns {JSX.Element}
*/
export function Container2(props: ContainerProps): JSX.Element {
return <Container>{props.children}</Container>;
}