Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81165 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 createFullPageComponent
10
* @typechecks
11
*/
12
13
"use strict";
14
15
// Defeat circular references by requiring this directly.
16
var ReactCompositeComponent = require('ReactCompositeComponent');
17
var ReactElement = require('ReactElement');
18
19
var invariant = require('invariant');
20
21
/**
22
* Create a component that will throw an exception when unmounted.
23
*
24
* Components like <html> <head> and <body> can't be removed or added
25
* easily in a cross-browser way, however it's valuable to be able to
26
* take advantage of React's reconciliation for styling and <title>
27
* management. So we just document it and throw in dangerous cases.
28
*
29
* @param {string} tag The tag to wrap
30
* @return {function} convenience constructor of new component
31
*/
32
function createFullPageComponent(tag) {
33
var elementFactory = ReactElement.createFactory(tag);
34
35
var FullPageComponent = ReactCompositeComponent.createClass({
36
displayName: 'ReactFullPageComponent' + tag,
37
38
componentWillUnmount: function() {
39
invariant(
40
false,
41
'%s tried to unmount. Because of cross-browser quirks it is ' +
42
'impossible to unmount some top-level components (eg <html>, <head>, ' +
43
'and <body>) reliably and efficiently. To fix this, have a single ' +
44
'top-level component that never unmounts render these elements.',
45
this.constructor.displayName
46
);
47
},
48
49
render: function() {
50
return elementFactory(this.props);
51
}
52
});
53
54
return FullPageComponent;
55
}
56
57
module.exports = createFullPageComponent;
58
59