Fixed typing

This commit is contained in:
Lukian 2025-03-24 10:56:27 +01:00
parent ae1fea3790
commit 1f24907c80

View file

@ -2,10 +2,26 @@ import { useParams } from "react-router-dom";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import axios from "axios"; import axios from "axios";
type Channel ={
id: number,
name: string
description: string
}
type Message = {
id: number,
user_id: number,
username: string,
content: string,
date: number
}
type Messages = Message[]
export default function Channel() { export default function Channel() {
const { id } = useParams(); const { id } = useParams();
const [channel, setChannel] = useState({}); const [channel, setChannel] = useState<Channel>();
const [messages, setMessages] = useState([]); const [messages, setMessages] = useState<Messages>();
useEffect(() => { useEffect(() => {
axios.get(`/api/channels/${id}`).then((res) => { axios.get(`/api/channels/${id}`).then((res) => {
@ -17,6 +33,10 @@ export default function Channel() {
}); });
}, [id]); }, [id]);
if (!channel || !messages) {
return <div>Loading...</div>;
}
return ( return (
<div> <div>
<h1>Channel {channel.name}</h1> <h1>Channel {channel.name}</h1>