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

95
Views
useLocation in class components

HI I'm making a simple e-commerce website using: React, class-components, React-router, Redux, and Graphql endpoint.

I fetched the data of products from graphql endpoint and displayed it on the productsListing page. Now I want to make a ProductsDetail page, But I don't know how to pass specific product from productsListing page to ProductsDetail page. I am using React-router v6 for routing.

I was trying to pass the product data using the Link tag, to handle this.props.location.state on the productsDetail page.

products.length &&
      products.map((item) => {
        return (
          <Link key={item.id} to={"/PDP"} state={item}></Link>
          });

But on the ProductsDetail page, when I try to console.log(this. props) there is no location property. and when I try console.log(this.props.location.state) it says "Undefined".

As I think this problem is because I am using react-router v6 in class components.

My question is: Are there any other ways to handle this.props.location in react-router v6 without useLocation hook? If Not, then how to pass a specific product object from one page to another page?

Thank You.

about 4 years ago · Santiago Gelvez
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!