forked from gaearon/react-document-title
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 998 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var withSideEffect = require('react-side-effect');
function reducePropsToState(propsList) {
return DocumentTitle.join(propsList.map(function (e) { return e.title; }));
}
function handleStateChangeOnClient(title) {
var nextTitle = title || '';
if (nextTitle !== document.title) {
document.title = nextTitle;
}
}
function DocumentTitleBase() {}
DocumentTitleBase.prototype = Object.create(React.Component.prototype);
DocumentTitleBase.displayName = 'DocumentTitle';
DocumentTitleBase.propTypes = {
title: PropTypes.string.isRequired
};
DocumentTitleBase.prototype.render = function() {
if (this.props.children) {
return React.Children.only(this.props.children);
} else {
return null;
}
};
var DocumentTitle = module.exports = withSideEffect(
reducePropsToState,
handleStateChangeOnClient
)(DocumentTitleBase);
DocumentTitle.join = function (tokens) {
return tokens.pop();
};