generated from lucien/api-template
Fixed typing
This commit is contained in:
parent
ae1fea3790
commit
1f24907c80
1 changed files with 22 additions and 2 deletions
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue