Skip to content
Open
Prev Previous commit
Next Next commit
instalación axios y creación de datatable y Dashboard
  • Loading branch information
Juliandos committed Mar 3, 2025
commit a89e717b84ee14bed34afc4767b82a67bb0469d2
78 changes: 62 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"axios": "^1.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.85.1",
Expand Down
23 changes: 23 additions & 0 deletions src/components/Datatable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function DataTable({ data }) {
return (
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Título</th>
</tr>
</thead>
<tbody>
{data.map((album) => (
<tr key={album.id}>
<td>{album.id}</td>
<td>{album.title}</td>
</tr>
))}
</tbody>
</table>
);
}

export default DataTable;

44 changes: 39 additions & 5 deletions src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
import React from "react";
import { useState, useEffect } from "react";
import axios from "axios";
import DataTable from "../components/Datatable";

const Dashboard = () => {
return <h1>Howwla</h1>;
};
function Dashboard({ setIsAuthenticated }) {
const [albums, setAlbums] = useState([]);
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);

export default Dashboard;
useEffect(() => {
fetchData();
}, []);

const fetchData = async () => {
setLoading(true);
try {
const response = await axios.get(
`https://jsonplaceholder.typicode.com/albums?_limit=10&_page=${page}`
);
setAlbums((prev) => [...prev, ...response.data]);
setPage(page + 1);
} catch (error) {
console.error("Error al obtener los datos", error);
} finally {
setLoading(false);
}
};

return (
<div>
<h2>Dashboard</h2>
<button onClick={() => setIsAuthenticated(false)}>Cerrar sesión</button>
<DataTable data={albums} />
<button onClick={fetchData} disabled={loading}>
{loading ? "Cargando..." : "Ver más"}
</button>
</div>
);
}

export default Dashboard;