-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Warn when Router
is given >1 children
#4450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn when Router
is given >1 children
#4450
Conversation
As per issue remix-run#4444, this PR adds an invariant which provides a nicer error message from `Router` if it is given multiple children.
@@ -21,6 +22,11 @@ class Router extends React.Component { | |||
|
|||
render() { | |||
const { children } = this.props | |||
invariant( | |||
children == undefined || React.Children.count(children) === 1, | |||
'A <Router> must have at most one child element.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase must have at most
sounds odd to me. I think that A <Router> can only have one child element.
would be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would agree that that could be rephrased. I like yours better. Will see what everyone else thinks but happy to reword.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say A <Router> may have only one child element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing tests! Let's update the message to A <Router> may have only one child element
and we can merge :)
@mjackson done! 🎉 |
@mjackson the tests work locally - not sure why they have failed on Travis :/ |
Thanks, @jackfranklin! We'll get those Travis tests worked out soon, don't you worry ;) |
As per issue #4444, this PR adds an invariant which provides a nicer
error message from
Router
if it is given multiple children.Any feedback on the approach, etc, is very welcome! I hope it's OK :)