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

99
Views
Send prop with react route

I try to send a data called favProduct to Favourites component. When I send the data, I get undefined. How can I send a data when I use react route?

const [favProduct, setFavProduct] = useState([1,2,3,4,5]);


  return (
    <Router>
      <div className="App">
        <Header />
        <Switch>
          <Route path="/" exact component={Home}/>
          <Route path="/men" component={Men} />
          <Route path="/women" component={Women} />
          <Route path="/kids" component={Kids} />
          <Route path="/productBuy" component={ProductBuy} />
          <Route path="/favourites" component={Favourites} />
          <Route path="/cart" component={Cart} />
          <Route path="/checkout" component={Checkout} />
          <Route path="/addproduct" component={AddProduct} />
        </Switch>
        <Footer />
      </div>
    </Router>
  );
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you want, or need, to send additional props to routed components, use the Route's render prop to inject the props and forward the route props.

Example:

<Route
  path="/favourites"
  render={props => <Favourites {...props} favProduct={favProduct} />}
/>

Access all the route props as done previously, i.e. props.location, props.history, etc... and access the new prop that was passed, i.e. props.favProduct.

about 4 years ago · Juan Pablo Isaza Report

0

If using react-router v6+, in your route, try this:

<Route path="/favourites" element={<Favourites favProduct={favProduct} />} />
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!