Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule getReactRootElementInContainer
10
*/
11
12
"use strict";
13
14
var DOC_NODE_TYPE = 9;
15
16
/**
17
* @param {DOMElement|DOMDocument} container DOM element that may contain
18
* a React component
19
* @return {?*} DOM element that may have the reactRoot ID, or null.
20
*/
21
function getReactRootElementInContainer(container) {
22
if (!container) {
23
return null;
24
}
25
26
if (container.nodeType === DOC_NODE_TYPE) {
27
return container.documentElement;
28
} else {
29
return container.firstChild;
30
}
31
}
32
33
module.exports = getReactRootElementInContainer;
34
35