Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit a5834d60 authored by FadhilP's avatar FadhilP
Browse files

Add TopicList component

parent 9330a1f9
Branches
No related tags found
No related merge requests found
import React, { useEffect, useState } from "react";
import axios from 'axios'
import { Link } from "react-router-dom"
const LINK = 'http://localhost:4000';
export default function TopicList(props){
const [topics, setTopics] = useState([])
useEffect(() => {
const fetch = async () => {
const response = await axios.get(`${LINK}/api/topics`)
setTopics(response.data.data)
}
fetch()
}, [])
return (
<div>
<ul>
{topics.map((value) => (
<li>
<Link to={`/topic/${value.id}`}>{value.name}</Link>
</li>
))}
</ul>
</div>
)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment