Add a displayName to an anonymous component in Route
#1543
scottwillmoore
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
A common pattern is...
However, in the React developer tools the component is labelled
Anonymous. You can address this and lift the component out of the route.However, now you do not have access to
Routeand cannot use the hooks such asRoute.useParams().You can use a hoisted function instead, but I prefer to use arrow functions. You also cannot use the
FunctionComponenttype with a non-arrow functions.Solution
In
createRouteadd adisplayNameto the component if it does not already have anameordisplayName. ThedisplayNamecould just be the route path, for example/hi/in this case.All reactions