forked from plotly/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentTitle.react.js
40 lines (34 loc) · 948 Bytes
/
DocumentTitle.react.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
import {connect} from 'react-redux';
import {Component} from 'react';
import PropTypes from 'prop-types';
class DocumentTitle extends Component {
constructor(props) {
super(props);
const {update_title} = props.config;
this.state = {
initialTitle: document.title,
update_title,
};
}
UNSAFE_componentWillReceiveProps(props) {
if (this.state.update_title && props.isLoading) {
document.title = this.state.update_title;
} else {
document.title = this.state.initialTitle;
}
}
shouldComponentUpdate() {
return false;
}
render() {
return null;
}
}
DocumentTitle.propTypes = {
isLoading: PropTypes.bool.isRequired,
config: PropTypes.shape({update_title: PropTypes.string}),
};
export default connect(state => ({
isLoading: state.isLoading,
config: state.config,
}))(DocumentTitle);