I'm stuck with an issue that I have with React Router, I'm trying to render a component inside of a card but for some reasons, the data are not displaying:
<Link
to={{
pathname: `/job/${job._id}`,
state: job}}>
<p className="place">{job.workplace_name}</p>
<p className="location-job">{job.location}</p>
</Link>
on Click to this link I would like this to render:
const Articles = () => {
const query = (id) => {
fetch(`https://someurl.herokuapp.com/job/${id}`).then(res =>
console.log(res.json()))
}
const pathname = window.location.pathname.split('/');
const job_id = pathname[pathname.length - 1];
const job = query(job_id);
let position_name;
let workplace_name;
if (job) {
position_name = job.position_name;
workplace_name = job.workplace_name;
}
return (
<ArticleComponent
position_name={position_name}
workplace_name={workplace_name}
/>
);
};
Everything is displaying on the console.log
but for some reason, the job is not defined, so I can't pass any data to the ArticleComponent
, any ideas? Thanks in advance for the help, I have been stuck for quite some time now.