Fakultas Ilmu Komputer UI

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

add working custom Search component

parent 758fb0f8
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react'
import axios from 'axios'
import ThreadList from './ThreadList'
import { Link } from 'react-router-dom'
const API_URL = 'http://localhost:4000/api'
export default function Search(props) {
const [threads, setThreads] = useState([])
const searchParam = props.match.params.input
useEffect(() => {
const fetch = async () => {
const responseThreads = await axios.get(`${API_URL}/threads`)
const filteredThreads = responseThreads.data.data.filter(thread => thread.title.includes(searchParam))
setThreads(filteredThreads)
}
fetch()
}, [searchParam])
return (
<div>
<ul>
{threads.map((value) => (
<Link to={`/topic/${value.topic_name}/${value.id}` } style={{ textDecoration: 'none' }}>
<ThreadList
header={value.title}
user={value.username}
points={value.points}
time={value.updated_at}
topic={value.topic_name}>
</ThreadList>
</Link>
))}
</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