Provide a better error message (#12421)
Aaron Brager committed
Aug 16, 2018 at 09:54 UTC
8862172fa3d9f30ea6a7c1072bdae068e9794856
2 files changed
+20
-10
packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js
+10
-5
@@ -88,11 +88,16 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
88
let viewConfig;
89
if (!viewConfigs.has(name)) {
90
const callback = viewConfigCallbacks.get(name);
91
- invariant(
92
- typeof callback === 'function',
93
- 'View config not found for name %s',
94
- name,
95
- );
91
+ if (typeof callback !== 'function') {
92
+ invariant(
93
+ false,
94
+ 'View config not found for name %s.%s',
95
+ name,
96
+ typeof name[0] === 'string' && /[a-z]/.test(name[0])
97
+ ? ' Make sure to start component names with a capital letter.'
98
+ : '',
99
+ );
100
+ }
101
viewConfigCallbacks.set(name, null);
102
viewConfig = callback();
103
processEventTypes(viewConfig);
scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js
+10
-5
@@ -90,11 +90,16 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
90
let viewConfig;
91
if (!viewConfigs.has(name)) {
92
const callback = viewConfigCallbacks.get(name);
93
- invariant(
94
- typeof callback === 'function',
95
- 'View config not found for name %s',
96
- name,
97
- );
93
+ if (typeof callback !== 'function') {
94
+ invariant(
95
+ false,
96
+ 'View config not found for name %s.%s',
97
+ name,
98
+ typeof name[0] === 'string' && /[a-z]/.test(name[0])
99
+ ? ' Make sure to start component names with a capital letter.'
100
+ : '',
101
+ );
102
+ }
103
viewConfigCallbacks.set(name, null);
104
viewConfig = callback();
105
processEventTypes(viewConfig);