May 2019
Intermediate to advanced
496 pages
10h 38m
English
Passing down these props into your components should be your default method of accessing React Router state. You could use the withRouter higher-order component to avoid passing props, but that adds a significant amount of complexity to your code, including your tests.
Why can props be a problem? Well, let's look at an example from our codebase. There are actually a whole bunch of RouterButton elements in the button bar. They all get passed the same pathname prop:
<ToggleRouterButton id="limit-10" ... pathname={pathname}> 10</ToggleRouterButton><ToggleRouterButton id="limit-20" ... pathname={pathname}> 20</ToggleRouterButton><ToggleRouterButton id="limit-50" ... pathname={pathname}> 50</ToggleRouterButton><ToggleRouterButton ...Read now
Unlock full access