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

306
Views
How To Pass Props To Function Component use react-router-dom v6

I want to pass props into a function from the route, my code currently looks like this

Route

 <Route path="/person" render={(params) => <ProductDetails {...params} />} /> 

Code

function ProductDetails(props) {  
  return (  
    <div className="section has-text-centered mt-4">  
      console.log(props)  
      <h1>Hello</h1>  
    </div>  
  );  
};  
export default ProductDetails;

What am I missing here, please help.

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

0

In react-router-dom v6 you pass props to the routed component directly since they are passed as a ReactElement (a.k.a. JSX).

Example:

<Route path="person" element={<ProductDetails /* pass props here */ />} />

Based on your example snippet though, it sounds like your question it more specifically about passing the "route props" to a component. In RRDv6 there are no longer any route props, i.e. no history, location, and match props. Use the React hooks to access these: useNavigate for navigation, useLocation for location, and useMatch for match and useParams specifically for the route params.

import { useNavigate, useLocation, useParams } from 'react-router-dom';

function ProductDetails(props) {
  const navigate = useNavigate();
  const location = useLocation();
  const match = useMatch();

  useEffect(() => {
    console.log(props);
  }, [props]);

  return (  
    <div className="section has-text-centered mt-4"> 
      <h1>Hello</h1>  
    </div>  
  );  
};  
export default ProductDetails;
about 4 years ago · Juan Pablo Isaza Report

0

You can pass function with props in React Router DOM V6 in this way:

<Route path="/person" element={<ProductDetails render={(params) => ({ ...params })} />} />

And you can pass more props as names outside of render function.

Example:

<Route path="/person" element={<ProductDetails render={(params) => ({ ...params })} user={user} />} />
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!