Skip to content

Commit afb3b8b

Browse files
committed
Warn and do not attempt to render if store not instrumented
Very confusing error messages were produced if the container component returned by createDevTools() was constructed without a store being injected or if the store had not been instrumented with DevTools.instrument() Add warnings for both of these cases and avoid console error spam by short circuiting rendering of the devtools if they have not been setup correctly. Fixes #179
1 parent 23d99f9 commit afb3b8b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/createDevTools.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,36 @@ export default function createDevTools(children) {
2424

2525
constructor(props, context) {
2626
super(props, context);
27+
28+
if (!props.store && !context.store) {
29+
console.error(
30+
`DevTools cannot render because no Redux store was injected via \
31+
props or <Provide>`);
32+
return;
33+
}
34+
2735
if (context.store) {
2836
this.liftedStore = context.store.liftedStore;
2937
} else {
3038
this.liftedStore = props.store.liftedStore;
3139
}
40+
41+
if (!this.liftedStore) {
42+
console.error(
43+
`DevTools cannot render because the store not been instrumented \
44+
with DevTools.instrument()`);
45+
}
3246
}
3347

3448
render() {
49+
if (!this.liftedStore) {
50+
return null;
51+
}
52+
3553
return (
3654
<ConnectedMonitor {...monitorProps}
3755
store={this.liftedStore} />
3856
);
3957
}
4058
};
4159
}
42-

0 commit comments

Comments
 (0)