forked from gaearon/react-document-title
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (27 loc) · 734 Bytes
/
index.js
File metadata and controls
33 lines (27 loc) · 734 Bytes
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
'use strict';
var React = require('react'),
PropTypes = require('prop-types'),
withSideEffect = require('react-side-effect');
function reducePropsToState(propsList) {
var innermostProps = propsList[propsList.length - 1];
if (innermostProps) {
return innermostProps.title;
}
}
function handleStateChangeOnClient(title) {
var nextTitle = title || '';
if (nextTitle !== document.title) {
document.title = nextTitle;
}
}
function DocumentTitle(props) {
return props.children || null;
}
DocumentTitle.displayName = 'DocumentTitle';
DocumentTitle.propTypes = {
title: PropTypes.string.isRequired
};
module.exports = withSideEffect(
reducePropsToState,
handleStateChangeOnClient
)(DocumentTitle);