import React, { useState, useEffect } from 'react'; import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell, TableCaption } from './ui/table'; import { Button } from './ui/button'; const DataTable = () => { const [data, setData] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); // Mock data for demonstration - replace with actual MongoDB data const mockData = [ { id: 1, name: 'John Doe', email: 'john@example.com', role: 'Developer' }, { id: 2, name: 'Jane Smith', email: 'jane@example.com', role: 'Designer' }, { id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'Manager' }, { id: 4, name: 'Alice Brown', email: 'alice@example.com', role: 'Developer' }, { id: 5, name: 'Charlie Wilson', email: 'charlie@example.com', role: 'Designer' }, ]; useEffect(() => { // Simulate loading data setTimeout(() => { setData(mockData); setLoading(false); }, 1000); }, []); const fetchFromMongoDB = async () => { try { setLoading(true); // Replace this with your actual MongoDB connection logic // const response = await fetch('/api/data'); // const result = await response.json(); // setData(result); // For now, using mock data setData(mockData); } catch (err) { setError('Failed to fetch data'); } finally { setLoading(false); } }; if (loading) { return (
Loading...
); } if (error) { return (
{error}
); } return (

User Data

A list of users from the database. ID Name Email Role {data.map((user) => ( {user.id} {user.name} {user.email} {user.role} ))}
); }; export default DataTable;