-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobSearch.jsx
More file actions
40 lines (36 loc) · 1.03 KB
/
JobSearch.jsx
File metadata and controls
40 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useState } from "react";
import axios from "axios";
export default function JobSearch() {
const [keyword, setKeyword] = useState("");
const [jobs, setJobs] = useState([]);
const searchJobs = async () => {
try {
const res = await axios.get(`http://localhost:5000/search?keywords=${keyword}`);
setJobs(res.data.jobs); // Ensure this matches backend response format
} catch (error) {
console.error("Error searching jobs:", error);
}
};
return (
<div>
<input
type="text"
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
placeholder="Enter skill (e.g. JavaScript)"
/>
<button onClick={searchJobs}>Search Jobs</button>
<ul>
{jobs.length > 0 ? (
jobs.map((job) => (
<li key={job.id}>
<strong>{job.title}</strong> - {job.description}
</li>
))
) : (
<p>No jobs found</p>
)}
</ul>
</div>
);
}