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
Route
and 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
FunctionComponent
type with a non-arrow functions.Solution
In
createRoute
add adisplayName
to the component if it does not already have aname
ordisplayName
. ThedisplayName
could just be the route path, for example/hi/
in this case.Beta Was this translation helpful? Give feedback.
All reactions