Skip to content

Commit

Permalink
chore(layer): add console warning for missing BaseProvider/LayersMana…
Browse files Browse the repository at this point in the history
…ger (uber#2655)

* chore(layer): add console warning for missing BaseProvider/LayersManager

* chore(layer): add relevant link to documentation site in warning

* chore(layer): check for __DEV__ before warning

Co-authored-by: Chase Starr <[email protected]>
  • Loading branch information
foodforarabbit and chasestarr committed Jan 21, 2020
1 parent 1316414 commit 642dd40
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/layer/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ class LayerComponent extends React.Component<
state = {container: null};

componentDidMount() {
const {onMount, mountNode} = this.props;
const {onMount, mountNode, host: layersManagerHost} = this.props;
if (mountNode) {
onMount && onMount();
return;
}

// There was no LayersManager added if this.props.host === undefined.
// Use document.body is the case no LayersManager is used.
const host =
this.props.host !== undefined ? this.props.host : document.body;
const hasLayersManager = layersManagerHost !== undefined;
if (__DEV__) {
if (!hasLayersManager) {
console.warn(
'`LayersManager` was not found. This occurs if you are attempting to use a component requiring `Layer` without using the `BaseProvider` at the root of your app. Please visit https://baseweb.design/components/base-provider/ for more information',
);
}
}
const host = hasLayersManager ? layersManagerHost : document.body;
if (host) {
this.addContainer(host);
}
Expand Down

0 comments on commit 642dd40

Please sign in to comment.