reactjsreact-routerreact-router-domreact-router-v4react-router-component

React Route Component prop


Does anyone know why you will call the component in this way. () => <Component/> inside the route enter image description here


Solution

  • If you wanna pass new props (eg. isAuth below example) or access props from React Router (eg. history, location, match)

    <Route component={({history, location, match}) => <Component isAuth={isAuth} />} />