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

Ice_mank
- 410
- 3
- 8
-
It is like passing an entire component as a prop. Please refer to this link. https://stackoverflow.com/questions/39652686/pass-react-component-as-props – K.Raj. Nov 11 '20 at 06:21
-
if my solution worked for you please accept my answer – Gayatri Dipali Nov 12 '20 at 02:26
2 Answers
2
You don't really have to do it this but if that works its just fine, i prefer doing it this way:
<Route exact path="/business" component={BusinessLanding} />
I hope this clears your doubt that there is no need to call a component like this () => <Component/>
when you dont want to pass any props to the component
If you want to pass props you can do it this way:
<Route exact path="/business" component={({isOpen})=> <BusinessLanding open={isOpen} />} />

Gayatri Dipali
- 1,171
- 4
- 16
-
Don't forget to upvote helpful answers and accept when you can the ones that solved your problem. Glad to help – Gayatri Dipali Nov 11 '20 at 04:52
-
if you think my answer is correct or useful kindly upvote it and if you agree that my answer is correct consider accepting it (you can do it by clicking the tick icon on the left of my answer) – Gayatri Dipali Nov 11 '20 at 09:02
2
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} />} />

Kerem atam
- 2,387
- 22
- 34