From 5a8dbc6347b3541e84fe669b22c17ad3b715e258 Mon Sep 17 00:00:00 2001
From: Mitja Felicijan <mitja.felicijan@gmail.com>
Date: Wed, 21 Jan 2026 20:22:09 +0100
Subject: Engage!

---
 samples/test.tsx | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 samples/test.tsx

(limited to 'samples/test.tsx')

diff --git a/samples/test.tsx b/samples/test.tsx
new file mode 100644
index 0000000..0578ce4
--- /dev/null
+++ b/samples/test.tsx
@@ -0,0 +1,107 @@
+// Sample.tsx
+// A practical TSX + React + TypeScript example 🧩
+
+import React, { useEffect, useState } from "react";
+
+// --------------------
+// Types & Interfaces
+// --------------------
+type Role = "USER" | "ADMIN";
+
+interface User {
+    id: number;
+    name: string;
+    role: Role;
+}
+
+// Props for a component
+interface UserCardProps {
+    user: User;
+    onSelect: (id: number) => void;
+}
+
+// --------------------
+// Reusable Component
+// --------------------
+const UserCard: React.FC<UserCardProps> = ({ user, onSelect }) => {
+    return (
+        <div style={{ border: "1px solid #ccc", padding: 12, marginBottom: 8 }}>
+            <h3>{user.name}</h3>
+            <p>Role: {user.role}</p>
+            <button onClick={() => onSelect(user.id)}>Select</button>
+        </div>
+    );
+};
+
+// --------------------
+// Main Component
+// --------------------
+const Sample: React.FC = () => {
+    // Typed state
+    const [users, setUsers] = useState<User[]>([]);
+    const [selectedUserId, setSelectedUserId] = useState<number | null>(null);
+    const [loading, setLoading] = useState<boolean>(true);
+
+    // --------------------
+    // Side Effects
+    // --------------------
+    useEffect(() => {
+        // Fake async fetch
+        const loadUsers = async () => {
+            setLoading(true);
+
+            await new Promise(resolve => setTimeout(resolve, 500));
+
+            setUsers([
+                { id: 1, name: "Alice", role: "USER" },
+                { id: 2, name: "Bob", role: "ADMIN" },
+            ]);
+
+            setLoading(false);
+        };
+
+        loadUsers();
+    }, []);
+
+    // --------------------
+    // Event Handlers
+    // --------------------
+    const handleSelectUser = (id: number) => {
+        setSelectedUserId(id);
+    };
+
+    // --------------------
+    // Derived Values
+    // --------------------
+    const selectedUser = users.find(u => u.id === selectedUserId);
+
+    // --------------------
+    // Conditional Rendering
+    // --------------------
+    if (loading) {
+        return <div>Loading users...</div>;
+    }
+
+    return (
+        <div style={{ maxWidth: 400, margin: "0 auto" }}>
+            <h2>User List</h2>
+
+            {users.map(user => (
+                <UserCard
+                    key={user.id}
+                    user={user}
+                    onSelect={handleSelectUser}
+                />
+            ))}
+
+            {selectedUser && (
+                <div style={{ marginTop: 16 }}>
+                    <strong>Selected User:</strong>
+                    <div>{selectedUser.name}</div>
+                </div>
+            )}
+        </div>
+    );
+};
+
+export default Sample;
-- 
cgit v1.2.3

