React / react-router - pass props to a child component using Router

0 points
Created by:

In this article, we would like to show you how to pass props to a child component using React Router.

Below we create MyComponent that receives props via Route element's render() method.

Then, we simply use to access the props.

Practical example:

import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';

const MyComponent = (props) => (
    { => (
      <li key={fruit}>{fruit},</li>

const App = () => {
  const fruits = ['🍏 Apple', '🍌 Banana', '🍒 Cherry'];

  return (
      <Route path="/" render={() => <MyComponent data={fruits} />} />

export default App;

You can run this example here.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

React - react-router

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂