I have the following code within a component called AllJobs
<TableCell>
<Link
to={`/job/${item.id}`}
style={{ textDecoration: 'underline', color: 'black' }}
>
{item.id}
</Link>
</TableCell>
When the user clicks on this link, it then calls the component JobDetails
as per below route, within my App.js file:
<Router>
<Switch>
<Route exact path="/job/:id">
<JobDetails />
</Route>
</Switch>
</Router>
My problem is, within my JobDetails
component, I have a useEffect that isn't being fired and unsure why it isn't as I need it to call my getJob()
function?
export default function JobDetails() {
const { id } = useParams();
const [currentJob, setCurrentJob] = useState([]);
const getJob = async () => {
console.log("Inside JobDetails for id:", id)
try {
const response = await fetch(`http://localhost:3000/get-job/${id}`);
const currentJobRec = await response.json();
console.log("current-job", currentJobRec)
setCurrentJob(currentJobRec);
} catch (err) {
console.error(err.message);
}
};
useEffect(() => {
getJob();
}, []);
Can anyone please assist as to what I am missing as I need to trigger off the useEffect().