Small changes
This commit is contained in:
parent
2885d1488f
commit
c237d0063d
2 changed files with 24 additions and 5 deletions
21
app/page.tsx
21
app/page.tsx
|
|
@ -1,9 +1,26 @@
|
|||
import RouteCards from '@/components/RouteCards';
|
||||
"use client"
|
||||
|
||||
import { CardTitle, Card, CardDescription, CardHeader, CardContent } from '@/components/ui/card';
|
||||
import { getRoutes } from '@/lib/serverActions';
|
||||
import RouteCards from '@/components/RouteCards';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default async function Home() {
|
||||
async function fetchRoutes() {
|
||||
let routes: Route[] = await getRoutes();
|
||||
return routes;
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
const data: Route[] = await fetchRoutes();
|
||||
setRoutes(data);
|
||||
}
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
const [routes, setRoutes] = useState<Route[]>([])
|
||||
|
||||
return (
|
||||
<main>
|
||||
|
|
|
|||
|
|
@ -10,17 +10,18 @@ import React, { useState } from 'react';
|
|||
class RouteCards extends React.Component<{routes: Route[]}> {
|
||||
constructor(props: { routes: Route[] }) {
|
||||
super(props);
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
routes: this.props.routes,
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<{ routes: Route[]; }>, prevState: Readonly<{}>, snapshot?: any): void {
|
||||
if (prevProps.routes !== this.props.routes) {
|
||||
componentDidUpdate(prevProps: Readonly<{ routes: Route[]; }>, prevState: Readonly<{}>) {
|
||||
if (this.props.routes !== prevProps.routes) {
|
||||
this.setState({
|
||||
routes: this.props.routes
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +49,7 @@ class RouteCards extends React.Component<{routes: Route[]}> {
|
|||
|
||||
|
||||
|
||||
|
||||
handleClick = (route: Route) => {
|
||||
console.log(route);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue