Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
How do I pass my id to the file SinglePost when I'm using on click navigate

Where the click happen:

<img onClick={() => {navigate("/single")}} className="postImages" src={post.img_url} alt={post.title} />

And here is the hole component:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can pass it as a state (I assume post has an id field, feel free to change it if it's not):

<img
  onClick={() => navigate("/single", { state: { id: post.id } })}
  className="postImages"
  src={post.img_url}
  alt={post.title}
/>

And grab it in SinglePost with the help of useLocation from React Router Dom:

// import the hook at the top of the component
import {useLocation} from "react-router-dom";
// use it inside the component
const { state } = useLocation();
console.log(state.id);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!