Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit e4857b6

Browse files
Use react-is to check valid components
1 parent a25fbf6 commit e4857b6

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"hoist-non-react-statics": "^3.0.1",
4444
"path-to-regexp": "^1.7.0",
4545
"query-string": "^6.2.0",
46+
"react-is": "^16.5.2",
4647
"react-lifecycles-compat": "^3.0.4"
4748
},
4849
"devDependencies": {

src/routers/getScreenForRouteName.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isValidElementType } from 'react-is';
2+
13
import invariant from '../utils/invariant';
24

35
/**
@@ -23,7 +25,7 @@ export default function getScreenForRouteName(routeConfigs, routeName) {
2325
if (typeof routeConfig.getScreen === 'function') {
2426
const screen = routeConfig.getScreen();
2527
invariant(
26-
typeof screen === 'function',
28+
isValidElementType(screen),
2729
`The getScreen defined for route '${routeName} didn't return a valid ` +
2830
'screen or navigator.\n\n' +
2931
'Please pass it like this:\n' +

src/routers/validateRouteConfigMap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isValidElementType } from 'react-is';
2+
13
import invariant from '../utils/invariant';
24

35
/**
@@ -17,9 +19,7 @@ function validateRouteConfigMap(routeConfigs) {
1719

1820
if (
1921
!screenComponent ||
20-
(typeof screenComponent !== 'function' &&
21-
typeof screenComponent !== 'string' &&
22-
!routeConfig.getScreen)
22+
(!isValidElementType(screenComponent) && !routeConfig.getScreen)
2323
) {
2424
throw new Error(`The component for route '${routeName}' must be a React component. For example:
2525

0 commit comments

Comments
 (0)